【发布时间】:2011-08-10 12:04:37
【问题描述】:
使用 Python 将非抗锯齿字体(例如 ttf 字体)渲染到内部图像(例如 PIL.Image,即我不需要显示它)的最快速和准确的方法是什么?我说准确是因为我不久前用 pygame 尝试过,我给它的大小渲染的字体与 Word 或 Paint 中渲染的窗口不匹配。
【问题讨论】:
标签: python image fonts render truetype
使用 Python 将非抗锯齿字体(例如 ttf 字体)渲染到内部图像(例如 PIL.Image,即我不需要显示它)的最快速和准确的方法是什么?我说准确是因为我不久前用 pygame 尝试过,我给它的大小渲染的字体与 Word 或 Paint 中渲染的窗口不匹配。
【问题讨论】:
标签: python image fonts render truetype
Python Imaging Library (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://mail.python.org/pipermail/image-sig/2005-August/003497.html
【讨论】:
啊this is how it's done... 应该呈现与 windows at is 使用其算法相同的渲染。
【讨论】: