moviepy.video.VideoClip.TextClip#

class moviepy.video.VideoClip.TextClip(font, text=None, filename=None, font_size=None, size=(None, None), margin=(None, None), color='black', bg_color=None, stroke_color=None, stroke_width=0, method='label', text_align='left', horizontal_align='center', vertical_align='center', interline=4, transparent=True, duration=None)[source]#

Class for autogenerated text clips.

Creates an ImageClip originating from a script-generated text image.

Parameters:
  • font – Path to the font to use. Must be an OpenType font.

  • text – A string of the text to write. Can be replaced by argument filename.

  • filename – The name of a file in which there is the text to write, as a string or a path-like object. Can be provided instead of argument text

  • font_size – Font size in point. Can be auto-set if method=’caption’, or if method=’label’ and size is set.

  • size – Size of the picture in pixels. Can be auto-set if method=’label’ and font_size is set, but mandatory if method=’caption’. the height can be None for caption if font_size is defined, it will then be auto-determined.

  • margin – Margin to be added arround the text as a tuple of two (symmetrical) or four (asymmetrical). Either (horizontal, vertical) or (left, top, right, bottom). By default no margin (None, None). This is especially usefull for auto-compute size to give the text some extra room.

  • color – Color of the text. Default to “black”. Can be a RGB (or RGBA if transparent = True) tuple, a color name, or an hexadecimal notation.

  • bg_color – Color of the background. Default to None for no background. Can be a RGB (or RGBA if transparent = True) tuple, a color name, or an hexadecimal notation.

  • stroke_color – Color of the stroke (=contour line) of the text. If None, there will be no stroke.

  • stroke_width – Width of the stroke, in pixels. Must be an int.

  • method

    Either :
    • ’label’ (default), the picture will be autosized so as to fit the text either by auto-computing font size if width is provided or auto-computing width and eight if font size is defined

    • ’caption’ the text will be drawn in a picture with fixed size provided with the size argument. The text will be wrapped automagically, either by auto-computing font size if width and height are provided or adding line break when necesarry if font size is defined

  • text_align – center | left | right. Text align similar to css. Default to left.

  • horizontal_align – center | left | right. Define horizontal align of text bloc in image. Default to center.

  • vertical_align – center | top | bottom. Define vertical align of text bloc in image. Default to center.

  • interline – Interline spacing. Default to 4.

  • transparentTrue (default) if you want to take into account the transparency in the image.

  • duration – Duration of the clip

  • note:: (..) –

    ** About final TextClip size **

    The final TextClip size will be of the absolute maximum height possible for the font and the number of line. It specifically mean that the final height might be a bit bigger than the real text height, i.e, absolute bottom pixel of text - absolute top pixel of text. This is because in a font, some letter go above standard top line (e.g letters with accents), and bellow standard baseline (e.g letters such as p, y, g).

    This notion is knowned under the name ascent and descent meaning the highest and lowest pixel above and below baseline

    If your first line dont have an “accent character” and your last line dont have a “descent character”, you’ll have some “fat” arround