Python 使用PIL.ImageFont.truetype加载otf文件时文件格式未知
我正在使用PIL模块加载字体文件。但出现了错误:未知的文件格式。 我加载的是一个otf文件,我正在使用PIL.ImageFont.truetype函数。应该没问题,但事实并非如此 我搜索了有关PLT的文档,我确信它的功能是正确的Python 使用PIL.ImageFont.truetype加载otf文件时文件格式未知,python,fonts,python-imaging-library,Python,Fonts,Python Imaging Library,我正在使用PIL模块加载字体文件。但出现了错误:未知的文件格式。 我加载的是一个otf文件,我正在使用PIL.ImageFont.truetype函数。应该没问题,但事实并非如此 我搜索了有关PLT的文档,我确信它的功能是正确的 from PIL import Image, ImageDraw, ImageFont fontsize = 50 font = ImageFont.truetype('./NotoSansCJKjp-Regular.otf', fontsize, encoding
from PIL import Image, ImageDraw, ImageFont
fontsize = 50
font = ImageFont.truetype('./NotoSansCJKjp-Regular.otf', fontsize, encoding='utf-8')
我希望有一个字体对象,但实际是:
OSError Traceback (most recent call last)
<ipython-input-4-48a2319a31ba> in <module>
9 #!del NotoSansCJKjp-hinted.zip
10
---> 11 font = ImageFont.truetype('./NotoSansCJKjp-Regular.otf', fontsize, encoding='utf-8')
12 #font = ImageFont.load('NotoSansCJKjp-Regular.otf')
~\.conda\envs\for_kaggle\lib\site-packages\PIL\ImageFont.py in truetype(font, size, index, encoding, layout_engine)
544
545 try:
--> 546 return freetype(font)
547 except IOError:
548 if not isPath(font):
~\.conda\envs\for_kaggle\lib\site-packages\PIL\ImageFont.py in freetype(font)
541
542 def freetype(font):
--> 543 return FreeTypeFont(font, size, index, encoding, layout_engine)
544
545 try:
~\.conda\envs\for_kaggle\lib\site-packages\PIL\ImageFont.py in __init__(self, font, size, index, encoding, layout_engine)
159 return
160 self.font = core.getfont(
--> 161 font, size, index, encoding, layout_engine=layout_engine
162 )
163 else:
OSError: unknown file format
请在开始之前包含以下代码行
----**font = ImageFont.truetype('./NotoSansCJKjp-Regular.otf', fontsize, encoding='utf-8')**
!wget -q --show-progress https://noto-website-2.storage.googleapis.com/pkgs/NotoSansCJKjp-hinted.zip
!unzip -p NotoSansCJKjp-hinted.zip NotoSansCJKjp-Regular.otf > NotoSansCJKjp-Regular.otf
!rm NotoSansCJKjp-hinted.zip