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

相关文章:

  • 2021-07-19
  • 2022-12-23
  • 2021-06-29
  • 2021-08-24
  • 2021-12-18
  • 2022-12-23
  • 2022-01-17
  • 2021-04-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2021-08-06
  • 2021-12-04
  • 2021-07-14
相关资源
相似解决方案