我很困惑,因為當我嘗試保存影像的調整大小版本時,它顯示“AttributeError: 'NoneType' object has no attribute 'save''。我查看了互聯網并查看了這個問題:Python Pillow 的縮略圖方法回傳 None但我已經使用了保存功能,所以我不明白為什么它不起作用。這是我的代碼:
from PIL import Image
imgg = Image.open('cropped.tif')
new_image = imgg.thumbnail((400, 400))
new_image.save('thumbnail_400.tif')
我敢打賭這是愚蠢的,但我看不出它是什么。我很感激任何幫助。
uj5u.com熱心網友回復:
thumbnail()是一個沒有回傳物件的擴展方法。該new_image變數將保留None在您的情況下。你需要這樣做。
from PIL import Image
imgg = Image.open('cropped.tif')
imgg.thumbnail((400, 400))
imgg.save('thumbnail_400.tif')
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/380447.html
