gpt4 book ai didi

Python - 枕头缩略图创建错误

转载 作者:太空宇宙 更新时间:2023-11-04 05:11:16 26 4
gpt4 key购买 nike

当我尝试从任何图像创建缩略图时,出现此错误:

TypeError: 'int' object has no attribute '__getitem__'

命令:

./manage.py shell
from PIL import Image
i = Image.open('1.jpg')
i.thumbnail(200)

错误信息:

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-3e0cd0330e45> in <module>()
----> 1 i.thumbnail(200)

/home/user/.virtualenvs/project/lib/python2.7/site-packages/PIL/Image.pyc
in thumbnail(self, size, resample)
1828 # preserve aspect ratio
1829 x, y = self.size
-> 1830 if x > size[0]:
1831 y = int(max(y * size[0] / x, 1))
1832 x = int(size[0])

TypeError: 'int' object has no attribute '__getitem__'

我在某处阅读了一些关于 libjpeg 包的内容,但我对所有类型的文件(gif,png,...) 都遇到了这个错误。

我使用 archlinux:

$ uname -a
Linux chalist 4.9.11-1-ARCH # 1 SMP PREEMPT
Sun Feb 19 13:45:52 UTC 2017 x86_64 GNU/Linux

最佳答案

大小需要是元组的形式,比如(200, 200)。所以你的新代码将是:

from PIL import Image
i = Image.open('1.jpg')
i.thumbnail((200, 200))

这是引用网页的链接:http://pillow.readthedocs.io/en/3.4.x/reference/Image.html#create-thumbnails

关于Python - 枕头缩略图创建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42941378/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com