Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PIL thumbnail with Image.ANTIALIAS. How to preserve quality

I'm trying to resize images while keeping aspect ratio. I use PIL's thumbnail method for this. I use Image.ANTIALIAS filter.

You can check my code here:

image = Image.open(design.design.path)
format = image.format
image = ImageOps.mirror(image)
new_size = (241, 241)
image.thumbnail(new_size, Image.ANTIALIAS)
image.save(response, format)

This code works perfectly however quality is lost after thumbnail. I can see it by zooming in on the saved image. I can see pixels at the corners of the image while I don't on the original image. This is seen even better when I print out resized image.

You can check out sample images here: http://imgur.com/a/ifZoU

Please tell me if you need anything else

like image 483
Marijus Avatar asked Oct 18 '22 22:10

Marijus


1 Answers

Image.save has options for you:

img.save(fpath, 'image/png', quality=100, optimize=True) 
like image 95
Farshid Ashouri Avatar answered Oct 22 '22 11:10

Farshid Ashouri