SmileyChris / easy-thumbnails

Easy thumbnails for Django
http://easy-thumbnails.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
1.37k stars 312 forks source link

animated gifs - preserve animation, as PIL/Pillow supports it #627

Open benzkji opened 5 months ago

benzkji commented 5 months ago

See original closed issue #184 - I created a new issue, for a fresh start and more visibility :-)

Pillow docs: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif-saving

Doing a quick test on my computer:

from PIL import Image

with Image.open("image.gif") as img:
    img.save("image-animation-removed.gif")

with Image.open("image.gif") as img:
    img.save("image-animation-preserved.gif", save_all=True)

This does exactly what filenames suggest. It supports animated GIFs (and probably animated webp as well, but I didnt test for these).

How about a setting: EASY_THUMBNAILS_PRESERVE_ANIMATIONS, to enable/disable animation preservation globally, in easy thumbnails? Also, to be backwards compatible?

I would be motivated to provide a PR. Digging through changelog, I saw THUMBNAIL_IMAGE_SAVE_OPTIONS, it may even already be possible?

benzkji commented 5 months ago

So, in theory this would work an be supported by Pillow. In real live, the original GifImagePlugin object very soon (when treated by easy thumbnail processors) becomes an PIL.Image object, and drops it's frames. I still think it should be possible to preserve GIF animations, but it would probably not be as easy as in the above snippet ;-)

benzkji commented 5 months ago

Also #217

benzkji commented 5 months ago

WIP PR: #628