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