【问题标题】:can't save the image after using PIL Image.thumbnail使用 PIL Image.thumbnail 后无法保存图像
【发布时间】:2022-01-14 06:25:26
【问题描述】:

我很困惑,因为当我尝试保存图像的调整大小版本时,它显示“AttributeError:'NoneType' object has no attribute 'save''。 我查看了互联网并查看了这个问题:Python Pillow's thumbnail method returning None 但我已经使用了保存功能,所以我不明白为什么它不起作用。 这是我的代码:

    from PIL import Image

    imgg = Image.open('cropped.tif')
    new_image = imgg.thumbnail((400, 400))
    new_image.save('thumbnail_400.tif')

我敢打赌这很愚蠢,但我看不出它是什么。感谢您的帮助。

【问题讨论】:

  • 这能回答你的问题吗? Python Pillow's thumbnail method returning None 下面的答案与他们在您已经找到的问题中所做的相同
  • 我在问题中发布了该帖子的链接。正如我所说,这对我来说还不够清楚。

标签: python image-processing python-imaging-library thumbnails


【解决方案1】:

thumbnail() 是一个没有返回对象的扩展方法。在您的情况下,new_image 变量将保持为 None。你需要这样做。

from PIL import Image

imgg = Image.open('cropped.tif')
imgg.thumbnail((400, 400))
imgg.save('thumbnail_400.tif')

【讨论】:

    猜你喜欢
    • 2019-12-17
    • 2013-11-08
    • 2019-07-14
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 2018-11-21
    • 2016-04-11
    • 2022-08-21
    相关资源
    最近更新 更多