matthewwithanm / django-imagekit

Automated image processing for Django. Currently v4.0
http://django-imagekit.rtfd.org/
BSD 3-Clause "New" or "Revised" License
2.26k stars 276 forks source link

How is it possible to optimize for image quality upon resize? [question] #459

Open simonfromla opened 6 years ago

simonfromla commented 6 years ago

Resizing an image to thumbnail size reduces quality drastically. Bumping up the 'quality' in options={} has almost no effect.

What are some ways we can bump up the quality of a resized pic? Are there some steps we can take--maybe during initial photo upload, or during save--that might allow for better resized quality?

Am I simply using it incorrectly?

vstoykov commented 6 years ago

Can you show me an example of an image created with Django ImageKit and another created with other tool but with better quality. Also you can post the options that you are giving to the Spec, versions of PIL/Pillow, OS version and original image in order to reproduce it.

simonfromla commented 6 years ago

happy_guy The base image

screen shot 2018-03-09 at 7 22 06 pm created using ImageKit

screen shot 2018-03-09 at 7 22 26 pm done by github

Spec options:

profile_photo_thumbnail = ImageSpecField(source='profile_photo', processors=[ResizeToFill(50, 50)], format='PNG', options={'quality': 100})

Versions:
pilkit==2.0 Pillow==4.3.0
Django==1.11.8

Originally created in Mac OS X 10.11.3

vstoykov commented 6 years ago

I see that the image created by GitHub is more sharp. By default ImageKit uses PIL.Image.ANTIALIAS (the same as PIL.Image.LANCZOS ) when resizing and probably this filter is makeing the image more blurry. Actually this should be the best filter from Pillow in respect to quality http://pillow.readthedocs.io/en/5.0.0/handbook/concepts.html#concept-filters

Probably will be better to add option to pass the filter to ResizeToFill if some of the options give better results in some situations and developer to be able to set them.

You can try to install pilkit from source and change these filters in the code (https://github.com/matthewwithanm/pilkit/blob/2.0/pilkit/processors/resize.py#L24) to see if some of them will give you better results or this is the best Pillow can do.

If some of them gives better result then we need to open new issue against pilkit to try to improve its logic of using Pillow.