python - wand - 文本换行 - 基于图像文件大小

标签 python python-3.x wand magickwand

您好,我正在尝试在图像上写文字。但是文字溢出来了。有什么方法可以将此类文本内容包裹起来以适合图像?

from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color

with Image(filename='/home/path/image.jpg').clone() as img:
    print('width =', img.width)
    print('height =', img.height)
    quote = input('quote:')
    with Drawing() as draw:
        draw.font = 'wandtests/assets/League_Gothic.otf'
        draw.fill_color=Color('red')
        draw.text_alignment= 'center'
        img.font_size=50
        draw.text(int(img.width/2),int(img.height/2), quote)
        print(draw.get_font_metrics(img,quote))
        draw(img)
        print('text drawn')
    img.save(filename='/home/path/image01.jpg')

给定的输入是:

"Success makes so many people hate you. I wish it wasn't that way. It would be wonderful to enjoy success without seeing envy in the eyes of those around you."

output image

最佳答案

不绘制文本,而是使用 caption Image 继承自 BaseImage 的方法。

关于python - wand - 文本换行 - 基于图像文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34517724/

相关文章:

python - 使用 Wand/ImageMagick Python 将文本字符串渲染为图像以计算长度

python - 在没有非 python 依赖项的情况下将 PDF 转换为图像

python - 为什么在OpenCV中为内核使用一个数组?

python - 是否有可能通过 pyGithub 获得发布

performance - 新项目 Python 3x PostgreSQL 9x 和 pg8000 1x DBAPI?

python-3.x - lxml 不支持 xpath 上的多个属性过滤器

python - 如何从内存中向 Tesseract 提供图像

c++ - 在 python 线程中调用 TBB 'parallel_for'

python - Numpy:将值插入数组以使数组有序的最快方法

python - Tkinter 窗口与线程不能很好地配合