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

Using postprocessor like jpegoptim or optiping? #481

Open jhancia opened 5 years ago

jhancia commented 5 years ago

Thank you for this very useful package. I want to have a thumbnail generated when user uploads a file, probably using celery. I see we can set the general quality and size. Wondering if it's possible to also run the thumbnail through a postprocessor optimizer like jpegoptim or optipng? These can apparently reduce the file size by almost 50% (read about this in another package). Is this easy to do/any guidance on how to do this?

vstoykov commented 5 years ago

This should probably be possible with custom processor, but I'm not sure what will happens if Pillow is opening optimized image and then save it to another file. Will it preserve the optimizations or thy will be loosed? These optimizers are working on file on the filesystem right? If so then using them in ImageKit can be somehow suboptimal:

  1. store the resulting image in temp file;
  2. run the optimizer;
  3. Open the resulting image and return it from the processor.

But if this is ok then why not. You can try to create custom processor for your project which will do the same, and then share the result with us ;)