我正在使用 PIL 创建图像,其中包含许多精确放置的文本字符串。 我的第一次尝试是将像素字体转换为 pil 兼容格式,如下所述 这里。 例如,我下载 Silkscreen 字体并将其转换:
otf2bdf -p 8pt -o fonts/slkscr.bdf fonts/slkscr.ttf
pilfont.py fonts/slkscr.bdf
然后我可以像这样在 PIL 中使用该字体:
import Image, ImageDraw, os, sys, ImageFont
im = Image.new("RGB", (40,10))
draw = ImageDraw.Draw(im)
fn = ImageFont.load('fonts/slkscr.pil')
draw.text((0,0), "Hello", font=fn)
del draw
# write to stdout
im.save(sys.stdout, "PNG")
但是,生成的图像 ()未反映字体应有的外观。
我应该使用什么程序来转换和使用像素字体,以便它们按预期呈现?
提前致谢。
I am creating images using PIL that contain numerous exactly placed text strings. My first attempt was to convert pixel fonts into the pil-compatible format as described here. For example, I download the Silkscreen font and convert it:
otf2bdf -p 8pt -o fonts/slkscr.bdf fonts/slkscr.ttf
pilfont.py fonts/slkscr.bdf
I can then use the font in PIL like so:
import Image, ImageDraw, os, sys, ImageFont
im = Image.new("RGB", (40,10))
draw = ImageDraw.Draw(im)
fn = ImageFont.load('fonts/slkscr.pil')
draw.text((0,0), "Hello", font=fn)
del draw
# write to stdout
im.save(sys.stdout, "PNG")
However, the resulting image () does not reflect what the font should look like.
What procedure should I be using to convert and use pixel fonts so that they render as intended?
Thanks in advance.
发布评论
评论(1)
尤里卡!
只需为 otf2bdf 指定 72 dpi 的分辨率(默认为 100):
现在, 看起来很棒!
Eureka!
Just needed to specify a resolution of 72 dpi (default is 100) for otf2bdf:
Now, looks great!