在使用font = ImageFont.truetype("arial.ttf", size=15)设置字体时,报错:OSError: cannot open resource
原因是:没有找到arial.ttf
因此,我们需要下载arial.ttf,粘贴到Fonts文件中
查Pillow ImageFont官方文档:
font – A filename or file-like object containing a TrueType font. If the file is not found in this filename, the loader may also search in other directories, such as the
fonts/
directory on Windows or/Library/Fonts/
,/System/Library/Fonts/
and~/Library/Fonts/
on macOS
我用的Mac,因此需要将arial.ttf粘贴到 /Library/Fonts/
, /System/Library/Fonts/
and ~/Library/Fonts/
中,再次运行脚本,不会在报错了