django-versatileimagefield icon indicating copy to clipboard operation
django-versatileimagefield copied to clipboard

Support for gifs

Open guy881 opened this issue 7 years ago • 3 comments

Hey, I think it would be a good idea to check if the file extension is .gif and return unchanged gif when called via .thumbnail or .crop. When gif is downsized it is no longer animating. What do you think?

guy881 avatar Jul 06 '17 09:07 guy881

I don't think that's a good idea.

Imagine a picture gallery with preview thumbnails of a certain size (let's say 50x50). Now someone uploads a 80x70 gif. That would destroy the layout of the gallery.

I do think, however, animating the cropped/thumbnailed gif would be the best opion here, as the frontend gets images in the expected size and they retain their animation.

Syberspace avatar Jul 07 '17 10:07 Syberspace

@Syberspace, right that would be the best option. Unfortunatelly gifs cropped/thumbnailed by this library doesn't animate, at least in my case.

guy881 avatar Jul 12 '17 15:07 guy881

The issue mostly lies with the Pillow library (PIL) - its Image.thumbnail and Image.crop methods do not support GIF animations.

However, there's a way to work around it by implementing custom sizers that process individual GIF frames separately. This gist has the basic principle, and it's pretty easy to create your own custom sizers that implement it. This worked well for me by extending the default CroppedImage and ThumbnailImage sizers and making a special case for gifs.

@guy881

Plonq avatar Feb 11 '20 04:02 Plonq