django-versatileimagefield
django-versatileimagefield copied to clipboard
Support for gifs
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?
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, right that would be the best option. Unfortunatelly gifs cropped/thumbnailed by this library doesn't animate, at least in my case.
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