Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

can't save the image after using PIL Image.thumbnail

I am quite confused cause when I try to save the resized version of an image it says ‘AttributeError: ‘NoneType’ object has no attribute ‘save”.
I looked over the internet and also to this question: Python Pillow's thumbnail method returning None but i already used the save function so i don’t get why it doesn’t work.
Here’s my code:

    from PIL import Image

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

I bet it’s something stupid but i can’t see what it is. I appreciate any help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

thumbnail() is an extension method without a return object. The new_image variable will stay None in your case. You need to do this.

from PIL import Image

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading