在運行PIL_test.py文件的時候報錯:(captcha)python
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/目錄下。get
而後定義font對象的時候寫上字體的存放的完整路徑it
font = ImageFont.truetype('/usr/share/fonts/arial.ttf', 36)。運行經過。test