Python文本到图像生成问题
我正在使用 PIL 加载各种字体并将文本绘制到图像上。在基本层面上,这一切都有效。
但是,我遇到了许多问题,例如字母被剪裁(主要是草书或有很多尾部的风格字体等)。 textsize() 确实返回宽度/高度值,但字母仍然被剪裁。 PIL 中似乎也没有方法来为字符生成指定更大的图像尺寸。另一个问题是垂直间距。 PIL 似乎为某些字体返回较大的高度值,因此行之间的垂直间距过大。
鉴于 PIL 明显的局限性,我正在寻找比 PIL 更先进的字体和文本处理系统。
上周我对此进行了大量研究(Google、Python 文档、Stackoverflow 等),我看到人们建议使用 Imagemagick 或 pango 和 cairo 的组合。然而,尽管我已经阅读和搜索了这些各自的技术,但我根本找不到任何与我想要做的事情相关的可用文档。 Imagemagick 有一些 Python 绑定,但它们似乎都已经过时了好几年。
这里的一些有用的灵魂可以给我指出一些关于如何使用 Pango/Cairo 和/或 Imagemagick 的教程吗?
I'm using PIL to load in various fonts and draw text to images. At the basic level, it all works.
However, I am running into a number of problems such as letters being clipped (mainly cursive or stylistic fonts with lots of tails and such). textsize() does return width/height values, yet letters are still clipped. There also doesn't seem to be methods in PIL to specify larger image sizes for the character generating. Another issue is the vertical spacing. It seems PIL returns large height values for certain fonts and thus the vertical spacing between lines is overly large.
I'm in search of a more advanced font and text handling system than PIL, given its apparent limitations.
I've been researching this a lot over the last week (Google, Python docs, Stackoverflow, etc) and I've seen people recommending to use either Imagemagick or a combination of pango and cairo. However, as much as I've read and searched for these respective technologies I am simply not finding any usable documentation that pertains to what I am trying to do. There are some Python bindings for Imagemagick, but they all seem several years out of date.
Can some of the helpful souls here on SO point me to some tutorials on how to use Pango/Cairo and/or Imagemagick?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Cairo Cookbook 有很多使用 Cairo 的示例,Python 例程几乎都是 C 例程的镜像。
The Cairo cookbook has a number of examples for using Cairo, and the Python routines are almost mirror images of the C routines.
我使用 PyGame 取得了一些不错的结果,但我不知道是否它一定会解决你的问题。
I've had some fine results with PyGame, but I don't know if it will necessarily solve your problem.