2011-04-21 35 views
1

什么是最快速的方式和准确渲染非反锯齿字体(如ttf字体)使用Python到内部图像(例如,一个PIL.Image,即我don不需要显示它)?我说准确,因为我用pygame试了一下,而且我给它的大小的渲染字体与Word或Paint中渲染的窗口不匹配。蟒蛇渲染非反别名字体到内部图像

回答

7

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://mail.python.org/pipermail/image-sig/2005-August/003497.html

Python Imaging Library - Text rendering

+0

啊这个不准确就是我的意思。但我已经发布了另一个关于它的问题[这里](http://stackoverflow.com/questions/5748973/why-is-my-truetype-font-of-size-11-rendering-different-than-windows)。 – Claudiu 2011-04-21 19:41:01

+0

啊这实际上把它作为反锯齿,我想它不是。任何提示如何做到这一点? – Claudiu 2011-04-21 20:09:43

+0

@Claudiu根据此页面编辑回答:http://mail.python.org/pipermail/image-sig/2005-August/003497.html – elliot42 2011-04-21 21:26:15