python - 使 MoviePy 中的文本在宽度和高度之间自动调整大小作为 TextClip

标签 python imagemagick moviepy

我试图让我在 MoviePy 中的代码中的文本自动调整到屏幕中心(目前正在这样做),但我不想设置字体大小。我试图让文本大小适应宽度和高度,以便它自动调整自己的大小,但我无法终生弄清楚我做错了什么。

我可以让它以设定的字体大小显示,但只要我尝试自动调整大小,文本就会加载。

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)
      )

最佳答案

您可以使用 TextClip 类的method='caption' 属性:

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)
      )

关于python - 使 MoviePy 中的文本在宽度和高度之间自动调整大小作为 TextClip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53880756/

相关文章:

python - OpenCV 3.1 绘制轮廓 '(-215) npoints > 0'

python - 如何在 Python 中连接文本文件?

python - 计算多个 xarray 变量的平均值

imagemagick - 使用 imagemagick 组合图 block 以创建图像

python - Moviepy OSError Exec 格式错误 - 缺少 Shebang?

Python3.5 : Class initialization using inheritance

c++ - 如何使用由 png 数据构造的 blob 初始化 Magick::Image 对象(png 由 cv::imencode 创建)

java - ImageMagick 版本 7 的比较命令问题

python - 使用 MoviePy 在视频上叠加图像

python - Python 中的高性能视频编辑