IOError: cannot open resource


在运行PIL_test.py文件的时候报错:

File "PIL_test.py", line 40, in <module>
font = ImageFont.truetype('/usr/share/fonts/Arial.ttf', 36)
File "/usr/lib64/python2.6/site-packages/PIL/ImageFont.py", line 205, in truetype
return FreeTypeFont(filename, size, index, encoding)
File "/usr/lib64/python2.6/site-packages/PIL/ImageFont.py", line 121, in __init__
self.font = _imagingft.getfont(file, size, index, encoding)
IOError: cannot open resource

原因是找不到字体的资源文件

解决办法:

从window下找到字体的资源文件,并拷贝到/usr/share/fonts/目录下。

然后定义font对象的时候写上字体的存放的完整路径

font = ImageFont.truetype('/usr/share/fonts/arial.ttf', 36)。运行通过。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM