python将非消除锯齿的字体渲染到内部图像

Cla*_*diu 1 python fonts image render truetype

什么是最快捷的方式和准确的呈现使用Python非反锯齿字体(如TTF字体)到内部的图像(例如一个PIL.Image,即我并不需要显示它)?我说准确,因为我用pygame尝试了一段时间后,我给它的大小的渲染字体与Word或Paint中渲染的窗口不匹配.

ell*_*t42 7

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)
Run Code Online (Sandbox Code Playgroud)

也可以看看:

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

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

Python Imaging Library - 文本呈现