如何将非抗锯齿字体渲染到内部图像?

2024-01-06

使用 Python 将非抗锯齿字体(例如 ttf 字体)渲染到内部图像(例如到PIL.Image,即我不需要显示它)?我说准确是因为我不久前用 pygame 尝试过它,并且我给它的渲染字体大小与 Word 或 Paint 中渲染的窗口不匹配。


Python 图像库 (PIL) 可以将文本渲染为图像——我不知道它是不准确,但我还没有完全测试过......

先前存在的问题的示例:

from PIL import Image
from PIL import ImageFont, ImageDraw

image = Image.new("RGBA", (288,432), (255,255,255))
usr_font = ImageFont.truetype("resources/HelveticaNeueLight.ttf", 25)
d_usr = ImageDraw.Draw(image)
d_usr.fontmode = "1" # this apparently sets (anti)aliasing.  See link below.
d_usr.text((105,280), "MYTEXT",(0,0,0), font=usr_font)

也可以看看:

http://www.pythonware.com/products/pil/ http://www.pythonware.com/products/pil/

http://mail.python.org/pipermail/image-sig/2005-August/003497.html http://mail.python.org/pipermail/image-sig/2005-August/003497.html

Python 图像库 - 文本渲染 https://stackoverflow.com/questions/5414639/python-imaging-library-text-rendering

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将非抗锯齿字体渲染到内部图像? 的相关文章

随机推荐