【问题标题】:How can I draw a curved text using python? Converting text to curved image?如何使用 python 绘制弯曲的文本?将文本转换为弯曲图像?
【发布时间】:2021-08-30 04:48:28
【问题描述】:

我想编写一个将给定文本转换为图像的 python 程序。网上有教程,但是我想把文字弯成一个圆。

假设我有文本“您的弯曲文本”。

我想在图像上绘制它并最终得到如下内容:

我检查了 Pillow 和 OpenCV。我可能犯了一个错误,但我认为它们没有任何弯曲给定文本的功能?

最好的方法是什么?

提前致谢。

【问题讨论】:

  • 我觉得很有帮助click here
  • 如果您想要矢量文件,您可能需要某种 SVG 解决方案。 SVGWrite 没有被积极开发,但它确实有一个 TextPath 方法可以做你想做的事。 Inkscape 有一个基于 Python 的 extension system

标签: 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 对标签的帮助:代码。

【讨论】:

  • 谢谢。我以前从没用过魔杖。我很高兴我知道了。
猜你喜欢
  • 2015-01-16
  • 1970-01-01
  • 2014-07-19
  • 1970-01-01
  • 2010-12-04
  • 2018-06-20
  • 1970-01-01
  • 2019-12-10
  • 1970-01-01
相关资源
最近更新 更多