在运行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)。运行通过。

posted on 2017-06-25 17:59  言止予思  阅读(7849)  评论(0编辑  收藏  举报