Ir para o conteúdo

Text

TextClipMaker

Bases: BaseClipMaker[BaseTextAsset]

A clip maker for text assets.

The process of text clip creation involves:

  1. Font and Text Preparation:

    • Loads system fonts using the specified font family
    • Wraps text to fit within video width
    • Calculates text dimensions
  2. Shadow Creation (if enabled):

    • Generates shadow layer with specified angle and distance
    • Applies blur effect and opacity
    • Handles shadow color and positioning
  3. Text Rendering:

    • Creates text layer with specified font and color
    • Applies stroke/outline effects
    • Handles text alignment and line height
    • Supports RGBA colors with transparency
  4. Image Composition:

    • Combines shadow and text layers if shadow enabled
    • Crops image to text boundaries
    • Creates temporary PNG file for MoviePy
  5. Clip Creation:

    • Converts rendered image to MoviePy clip
    • Sets position based on text parameters
    • Applies specified duration

Examples:

# Create a basic text clip
maker = TextClipMaker(duration=5.0, video_resolution=(1920, 1080))
clip = maker.make_clip(text_asset)

# Create clip with shadow
text_asset.params.has_shadow = True
clip = maker.make_clip(text_asset)  # Will add shadow effect

# Create clip with custom position
text_asset.params.position = AbsolutePosition(x=100, y=50)
clip = maker.make_clip(text_asset)  # Will position at x=100, y=50

# Create clip with custom font size
text_asset.params.font_size = 48
clip = maker.make_clip(text_asset)  # Will render text with font size 48