AttributeError: ‘NoneType’ object has no attribute ‘save’ | Pillow

from PIL import Image

img = Image.open("demo.png")

New_img=img.thumbnail((90,90), Image.ANTIALIAS)

New_img.save("deTT.png")

Traceback (most recent call last): File “/Users/sahejmundi/Desktop/projects/LiveProjects/XML_project/Task_4/img_re.py”, line 15, in

AttributeError: ‘NoneType’ object has no attribute ‘save’

Answer

The thumbnail() method reduces the size of the image passed to it “in situ” rather than returning a new, reduced image. So you actually need:

from PIL import Image

img = Image.open("demo.png")

# Reduce to thumbnail in place
img.thumbnail((90,90), Image.ANTIALIAS)

img.save("deTT.png")