Python – Enables text in MoviePy to automatically resize between width and height as a TextClip

Enables text in MoviePy to automatically resize between width and height as a TextClip… here is a solution to the problem.

Enables text in MoviePy to automatically resize between width and height as a TextClip

I’m trying to get the text in my code in MoviePy to automatically adjust to the center of the screen (currently doing so), but I don’t want to set the font size. I tried to adapt the text size to the width and height so that it automatically resized itself, but I couldn’t figure out for life what I was doing wrong.

I

can have it display at the set font size, but the text loads whenever I try to automatically resize.

screensize = (1000,500)

credits = (TextClip(txt_credits, color='black',
        font="Keep-Calm-Medium", kerning=-2, interline=-1, size = 
screensize)
      .set_duration(25)
      .set_start(5)
      )

Solution

You can use the method=’caption’ property of the TextClip class:

Method: either ‘label’ (default, the picture will be autosized so as to fit exactly the size) or ‘caption’ (the text will be drawn in a picture with fixed size provided with the size argument). If caption, the text will be wrapped automagically (sometimes it is buggy, not my fault, complain to the ImageMagick crew) and can be aligned or centered (see parameter align).

screensize = (1000,500)

credits = (TextClip(txt_credits, color='black',
        font="Keep-Calm-Medium", kerning=-2, interline=-1, size = 
screensize, method='caption')
      .set_duration(25)
      .set_start(5)
      )

Related Problems and Solutions