2024-06-01 07:05:44 发布
网友
使用Python将非抗锯齿字体(例如ttf字体)渲染到内部图像(例如,渲染到PIL.Image,即我不需要显示它)的最快速和准确的方法是什么?我之所以说准确,是因为我不久前在pygame上试用过,但渲染字体的大小与windows在Word或Paint中渲染的字体不匹配
PIL.Image
啊this is how it's done。。。应呈现与windows相同的内容,并使用其算法
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
Python Imaging Library - Text rendering
啊this is how it's done。。。应呈现与windows相同的内容,并使用其算法
Python Imaging Library(PIL)可以将文本渲染到图像中我不知道它不准确,但我还没有完全测试过它
一个预先存在的问题的示例:
另见:
http://www.pythonware.com/products/pil/
http://mail.python.org/pipermail/image-sig/2005-August/003497.html
Python Imaging Library - Text rendering
相关问题 更多 >
编程相关推荐