The title says it all. When oversized animated gif files are resized, only the first frame is preserved.
After a bit of research, it looks like the solution is to first coalesce the gif before resizing it. This “fills out” the incomplete frames so they can be resized, retaining the animation, by ImageMagick.
Seemingly paradoxically, this usually results in a larger file size than you started with. The coalescing process can be effectively reversed by optimizing the resized gif.
So, we have a few possible solutions:
Coalesce, resize, then optimize gifs rather than sending them through the same optimization process as other images.
Allow browsers to resize gifs client side.
Some more involved process resembling YouTube lazy embeds, where gifs don’t animate until you click / hover them. (See e.g. 9gag.com)
I don’t think it’s actually the job of the server to resize a giant animated GIF that’s so large it doesn’t even fit in the viewport. That’s a lot of work, particularly if we are preserving animation, and as you noted it can munge the compression.
Resizing on the client is not a bad idea, provided we can hard-code the dimensions in the width and height attributes – resizing “on the fly” and letting the browser decide the width/height leads to bouncing of the page as it shifts to accommodate the unknown (until render time) dimensions).
This idea has some merit as well, but seems kind of harsh… and would be dev work. Maybe if that only kicks in when the animated GIF is so large?
We have two definitions of “large” being used, one with regard to file size and one with regard to dimensions, so clarity is key.
I competely agree, so long as we’re talking solely about large dimensions. Resizing and compressing uploaded gifs seems reasonable if it’s done to save bandwidth and storage space.
I thought this was already done automatically? I’ve always seen dimensions added to my image markup. The problem is that they’re being (as you put it) munged server-side based on those dimensions. (Or maybe not based on those dimensions… I haven’t looked at the code for that.)