python引入PIL做验证码发现字体不支持
这里只给出出问题的函数代码吧,defcreate_strs():c_chars=get_chars()strs='%s'%''.join(c_chars)font=Ima...
这里只给出出问题的函数代码吧,
def create_strs():
c_chars = get_chars()
strs = ' %s ' % ' '.join(c_chars)
font = ImageFont.truetype('/Library/Fonts/Arial.ttf',18)#这里是photojudge.py的 line 38 font_width,font_height = font.getsize(strs)
draw.text(((width - font_width) / 3,(height - font_height) / 3),strs,font = font,fill = fg_color)
return ''.join(c_chars)
下面是错提示:
Traceback (most recent call last):
File "photojudge.py", line 64, in <module>
code_img = create_validate_code()[0]
File "photojudge.py", line 49, in create_validate_code
strs = create_strs()
File "photojudge.py", line 38, in create_strs
font = ImageFont.truetype('/Library/Fonts/Arial.ttf',18)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 228, in truetype
return FreeTypeFont(font, size, index, encoding)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 131, in __init__
self.font = core.getfont(font, size, index, encoding)
IOError: cannot open resource
是不支持38行的字体格式吗?如何查看支持哪种字体格式?或者安装可以使支持这种格式?请老师指点,谢谢. 展开
def create_strs():
c_chars = get_chars()
strs = ' %s ' % ' '.join(c_chars)
font = ImageFont.truetype('/Library/Fonts/Arial.ttf',18)#这里是photojudge.py的 line 38 font_width,font_height = font.getsize(strs)
draw.text(((width - font_width) / 3,(height - font_height) / 3),strs,font = font,fill = fg_color)
return ''.join(c_chars)
下面是错提示:
Traceback (most recent call last):
File "photojudge.py", line 64, in <module>
code_img = create_validate_code()[0]
File "photojudge.py", line 49, in create_validate_code
strs = create_strs()
File "photojudge.py", line 38, in create_strs
font = ImageFont.truetype('/Library/Fonts/Arial.ttf',18)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 228, in truetype
return FreeTypeFont(font, size, index, encoding)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 131, in __init__
self.font = core.getfont(font, size, index, encoding)
IOError: cannot open resource
是不支持38行的字体格式吗?如何查看支持哪种字体格式?或者安装可以使支持这种格式?请老师指点,谢谢. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询