无法在Python中使用PIL读取woff文件

时间:2020-03-31 06:48:43

标签: python python-imaging-library true-type-fonts woff

我试图执行ImageFont.truetype

您可以下载woff文件here

from PIL import Image, ImageDraw, ImageFont
font = ImageFont.truetype('89874f10.woff', 40)

但是,我收到以下错误消息。

Traceback (most recent call last):
  File "<pyshell#64>", line 1, in <module>
    font = ImageFont.truetype('89874f10.woff', 10)
  File "C:\Program Files\Python38\lib\site-packages\PIL\ImageFont.py", line 642, in truetype
    return freetype(font)
  File "C:\Program Files\Python38\lib\site-packages\PIL\ImageFont.py", line 639, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "C:\Program Files\Python38\lib\site-packages\PIL\ImageFont.py", line 187, in __init__
    self.font = core.getfont(
OSError: invalid argument

错误原因是什么?

如何解决问题?

非常感谢您。

1 个答案:

答案 0 :(得分:0)

我认为您需要安装 freetype 库来处理该问题,或者使用this之类的转换器将字体转换为传统的Truetype。