我已经安装了一个字体(burbank.ttf),我正试图在PIL中使用它。我仔细检查后,它已安装,但运行以下代码时出现错误:
from PIL import Image, ImageDraw, ImageFont
img = Image.open('blended.png')
draw = ImageDraw.Draw(img)
font = ImageFont.truetype('burbank.ttf, 15')
draw.text((256, 76.8), "test", font=font)
错误:
Traceback (most recent call last):
File "/home/pi/Desktop/Item Shop/txttest.py", line 5, in <module>
font = ImageFont.truetype('burbank.ttf, 15')
File "/home/pi/.local/lib/python3.8/site-packages/PIL/ImageFont.py", line 640, in truetype
return freetype(font)
File "/home/pi/.local/lib/python3.8/site-packages/PIL/ImageFont.py", line 637, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/home/pi/.local/lib/python3.8/site-packages/PIL/ImageFont.py", line 185, in __init__
self.font = core.getfont(
OSError: cannot open resource
我尝试过指定字体的直接路径,但不起作用。我对字体了解不多,但我将.otf文件转换为.ttf,以便与PIL一起使用
感谢您的帮助
可能会改变:
到
如果它不能解决你的问题。 一个可能的原因是:它找不到
burank.ttf
的路径,请尝试给出字体的所有路径相关问题 更多 >
编程相关推荐