解决问题
File "F:Python36\lib\site-packages\PIL\ImageFont.py", line 144, in __init__
self.font = core.getfont(font, size, index, encoding, layout_engine=layout_engine)
OSError: cannot open resource
解决思路
self.font = core.getfont(font, size, index, encoding, layout_engine=layout_engine)
OSError:无法打开资源,
两个原因
T1、加载的字体文件路径不对!,很有可能是加载的文件名字过长,文件名过长也不行的!
T2、加载的字体文件有问题!
解决方法
1、先参考StackOverflow网友的解答:https://stackoverflow.com/questions/47694421/pil-issue-oserror-cannot-open-resource
I have also met this issue on Windows 10 Pro with PIL 5.3.0.
On my machine, the error is caused by non-ASCII font file names. If I change the the font name to only contain ASCII characters, I can open the font without any error.
2、博主自己的解决办法
博主是因为加载字体的文件路径不对造成的!把字体放在同代码文件夹下边即可!博主更改加载路径的方法也成功!
大功告成!