【问题标题】:How can I draw a curved text using python? Converting text to curved image?如何使用 python 绘制弯曲的文本?将文本转换为弯曲图像?
【发布时间】:2021-08-30 04:48:28
【问题描述】:
我想编写一个将给定文本转换为图像的 python 程序。网上有教程,但是我想把文字弯成一个圆。
假设我有文本“您的弯曲文本”。
我想在图像上绘制它并最终得到如下内容:
我检查了 Pillow 和 OpenCV。我可能犯了一个错误,但我认为它们没有任何弯曲给定文本的功能?
最好的方法是什么?
提前致谢。
【问题讨论】:
标签:
python
python-3.x
opencv
python-imaging-library
【解决方案1】:
您可以在 ImageMagick 中使用 -distort arc 360 执行类似的操作。
convert -font Arial -pointsize 20 label:' Your Curved Text Your Curved Text ' -virtual-pixel Background -background white -distort Arc 360 -rotate -90 arc_circle_text.jpg
您也可以在 Python Wand 中执行此操作,它使用 ImageMagick,如下所示:
from wand.image import Image
from wand.font import Font
from wand.display import display
with Image() as img:
img.background_color = 'white'
img.font = Font('Arial', 20)
img.read(filename='label: Your Curved Text Your Curved Text ')
img.virtual_pixel = 'white'
# 360 degree arc, rotated -90 degrees
img.distort('arc', (360,-90))
img.save(filename='arc_text.png')
img.format = 'png'
display(img)
感谢 Eric McConville 对标签的帮助:代码。