Python图像库,ImageFont-IOE

2024-10-02 14:18:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我有python FotoBox脚本在我的Ubuntu labtop上运行得非常好,但是在运行Raspbian的Raspberry Pi上,脚本有以下问题:

pi@raspberrypi:~/Desktop/FotoBox $ python PythonCollage_31.py
    Traceback (most recent call last):
      File "PythonCollage_31.py", line 49, in <module>
        font = ImageFont.truetype("/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf", 80, 0, 'unic')
      File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 240, in truetype
        return FreeTypeFont(font, size, index, encoding)
      File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 137, in __init__
        self.font = core.getfont(font, size, index, encoding)
    IOError: unknown file format

我还尝试使用另一行代码创建font对象:

^{pr2}$

但结果是一样的。在

有字体的文件,肯定存在!在

pi@raspberrypi:~/Desktop/FotoBox $ ls -l /usr/share/fonts/truetype/msttcorefonts/
insgesamt 4
-rw-r--r-- 1 root root 128 Jun 17 22:04 Comic_Sans_MS.ttf

Tags: inpy脚本shareusrlinepifile
1条回答
网友
1楼 · 发布于 2024-10-02 14:18:44

的正确语法ImageFont.truetype这是:

ImageFont.truetype(file, size, encoding=value)

因此,如果在第四个参数的开头添加encoding=,请使用“”而不是“”,然后删除第三个参数,如下所示:

^{pr2}$

这对我很有用。在

相关问题 更多 >