python将非注释性字体呈现为内部imag

2024-05-29 10:00:27 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Python将非抗锯齿字体(例如ttf字体)渲染为内部图像(例如,到PIL.Image,即我不需要显示它)的最快速、最准确的方法是什么?我之所以说准确,是因为不久前我在pygame中尝试过,而我给出的字体大小与windows在Word或Paint中呈现的字体不匹配。在


Tags: 方法图像imagepilwindows字体ttfpygame
2条回答

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

this is how it's done。。。应该呈现与windows在使用它的算法相同。在

相关问题 更多 >

    热门问题