python - 在 PIL 中用 Webdings 绘图

标签 python fonts python-imaging-library

我有一个使用 PIL 呈现文本的 Python 程序,它适用于各种字体。但它只绘制带有 wingdings 或 webdings 的“缺失字形”矩形。

这是一个尝试绘制每个 unicode 字符的示例:

# Run this with .ttf file path as an argument, and also an encoding if you like.
# It will make 16 PNGs with all the characters drawn.
import sys
import Image, ImageDraw, ImageFont

size = 20
per = 64

chars = 0x10000
perpage = per*per

fontfile = sys.argv[1]
encoding = sys.argv[2] if len(sys.argv) > 2 else ''

font = ImageFont.truetype(sys.argv[1], size, encoding=encoding)

for page in range(0, chars//perpage):

    im = Image.new("RGB", (size*per+30, size*per+30), '#ffffc0')
    draw = ImageDraw.Draw(im)

    for line in range(0, per):
        for col in range(0, per):
            c = page*perpage + line*per + col
            draw.text((col*size, line*size), unichr(c), font=font, fill='black')

    im.save('allchars_%03d.png' % page)

使用 Arial.ttf(或者更好的 ArialUni.ttf),我得到了 16 个有趣的 PNG。搜索 PIL 的问题,一些符号字体需要指定它们的编码。如果我使用 Symbol.ttf,我会得到所有缺失的字形,直到我将“symb”指定为编码。

如何让 wingdings 工作?

最佳答案

我一定是之前做错了什么。 “symb”作为编码也适用于 wingdings!抱歉噪音...

关于python - 在 PIL 中用 Webdings 绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/422555/

相关文章:

r - 在 R 控制台中指定字体 - 多平台解决方案?

python - 计算两个图像之间的相似度百分比

模块的 Python 命名约定

python - 如何在Python中从 future 检索任务?

emacs - 如何让我的 Emacs 在 X11 上*始终*使用 6x13

html - 在 HTML 输入中调整文本光标的垂直位置(相对于文本本身)

python - 有什么方法可以捕获python中发生异常的确切行号

python - 推荐人、被推荐人、 parent 和 child

python - 无法使用 im.getcolors

python - 在python中随机选择图像内的200x200正方形