tachyon icon indicating copy to clipboard operation
tachyon copied to clipboard

Support for animated gifs

Open joehoyle opened this issue 8 years ago • 10 comments

Ideally resize, but if that's not possible, just return the original.

joehoyle avatar Feb 15 '16 17:02 joehoyle

The underlying Vips library doesn't support animated gifs (see: https://github.com/jcupitt/libvips/issues/235) but perhaps gifsicle could be used for resizing animated gifs once they've been detected? It's also possible to resize animated GIFs using ImageMagick's coalesce feature but I don't think it's as performant as gifsicle, which is optimized specifically for gifs.

joemcgill avatar Jan 11 '17 05:01 joemcgill

Doesn't appear that gifsicle has native Node support; there's a npm module but that just finds the executable.

Are there any Node libraries that do support GIFs?

rmccue avatar Jan 11 '17 08:01 rmccue

I've not yet found one that does gif support natively, so maybe going the ImageMagick/GM route is best until something better is found, since those libraries are available on Lamda.

joemcgill avatar Jan 11 '17 13:01 joemcgill

Yeah I had looked into this for a bit, but never found anything. I'd be open to doing it if we had a good node library, right now we just have animated gif detection to not resize animated gifs as that by default will just take the first frame,

joehoyle avatar Jan 11 '17 17:01 joehoyle

Might be able to help out here: we ran into a similar problem with a 10up client who wanted to be able to resize gifs while preserving animation. Since Gifsicle doesn't have native PHP bindings, we ended up running Gifsicle on the web server via passthru().

I wrote about the math behind it last summer, which was as much of the code that I could share without stepping on work-for-hire issues. Hopefully that'll help :)

(Thanks to @bswatson for bringing this to my attention)

stevegrunwell avatar Apr 27 '17 17:04 stevegrunwell

@stevegrunwell Thanks for the info, super useful! I looked into Gifsicle previously as well, but there's no native Node bindings, and we can't run arbitrary executables on Lambda. :(

That said, maybe it's worth us building those bindings out. Given that most of the complexity is on the Gifsicle side, I imagine the Node connection would be quite simple.

rmccue avatar Apr 28 '17 00:04 rmccue

From the libvips author:

libvips supports loading whole GIF images since 8.5, though not GIF save unfortunately

See https://github.com/jcupitt/libvips/issues/620

I'm not super concerned about it tbh, I think it's a lot more effort than it's worth, however it's a nice-to-have if it ever does happen. Leaving the ticket open for #thefuture.

rmccue avatar Apr 28 '17 14:04 rmccue

It appears it's in development! https://github.com/libvips/libvips/issues/839#issuecomment-375806193

At the end of the ticket is a user who is able to copy a jpeg to a gif, so maybe worth looking into again?

nathanielks avatar Nov 17 '18 01:11 nathanielks

Looking further, it appears Sharp has an issue tracking support: https://github.com/lovell/sharp/issues/1372.

The prebuilt libvips binaries provided by sharp do not include *magick. To take advantage, you will need to compile your own libvips with support for *magick and install it globally before installing sharp.

If I'm reading this right, we just need to compile our own copy of libvips before installing sharp to get this support?

nathanielks avatar Nov 17 '18 01:11 nathanielks

Looks like there has been some movement on the feature request upstream with a feature PR at https://github.com/lovell/sharp/pull/2012. What's interesting is that the team with the PR is running this on production, so I suspect it's much closer to being added upstream.

I recall seeing support for this on a recent VIP project as well - so maybe VIP did something custom for their support.

tareiking avatar Jul 16 '20 03:07 tareiking