python将非消除锯齿的字体渲染到内部图像 [英] python render non-anti-aliased font to internal image

查看:537
本文介绍了python将非消除锯齿的字体渲染到内部图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the most speedy way and accurate to render non-anti-aliased fonts (e.g. ttf fonts) using Python to an internal image (e.g. to a PIL.Image, i.e. I don't need to display it)? I say accurate because I tried it with pygame a while back and the rendered fonts at the size I gave it didn't match what windows rendered in Word or Paint.

推荐答案

Python Imaging Library(PIL)可以将文本呈现给图像 - 我不知道它是不准确,但我尚未对其进行全面测试...

Python Imaging Library (PIL) can render text to an image--I'm not aware of it being inaccurate, but I haven't fully tested it yet...

来自原有问题的示例:

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 - 文字渲染

这篇关于python将非消除锯齿的字体渲染到内部图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆