Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.09k stars 1.51k forks source link

text resize according to the width and height in a video. #2037

Open THECH13F opened 9 months ago

THECH13F commented 9 months ago

i am making a automated system so that adds text generated by ai will add to a video so i want that i have specified a box width and height and a standard text size so if the text size increase the width and height of the box then it cuts the text but i want that it should decrease the font size untill it fits the box so if you guyz has a solution please help me with that.

thank you

anujpaude1 commented 9 months ago

If text size is resulting overflow of text, it results in IOError. Based on that, you can use try and catch with recursion until it's finally fits.

def texto(font_size):
    try:
        text = TextClip(" ").set_duration(duration)
    except IOError:
        return texto(font_size-4)
    return text 

Worked for me.

THECH13F commented 9 months ago

If text size is resulting overflow of text, it results in IOError. Based on that, you can use try and catch with recursion until it's finally fits.

def texto(font_size):
    try:
        text = TextClip(" ").set_duration(duration)
    except IOError:
        return texto(font_size-4)
    return text 

Worked for me.

not it does not return any error so how will it handle it?