Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust the quality of a resized image in Python Imaging Library?

I am working on PIL and need to know if the image quality can be adjusted while resizing or thumbnailing an image. From what I have known is the default quality is set to 85. Can this parameter be tweaked during resizing?

I am currently using the following code:

image = Image.open(filename) image.thumbnail((x, y), img.ANTIALIAS) 

The ANTIALIAS parameter presumably gives the best quality. I need to know if we can get more granularity on the quality option.

like image 329
bigmac Avatar asked Sep 10 '09 14:09

bigmac


1 Answers

Use PIL's resize method manually:

image = image.resize((x, y), Image.ANTIALIAS)  # LANCZOS as of Pillow 2.7 

Followed by the save method

quality_val = 90 image.save(filename, 'JPEG', quality=quality_val) 

Take a look at the source for models.py from Photologue to see how they do it.

like image 151
Dominic Rodger Avatar answered Sep 30 '22 04:09

Dominic Rodger