How to resize animate gifs without losing animation?

Archived from the Transloadit support forum. Originally posted on May 5, 2011; details may be outdated, see our docs for current behavior. Original thread

I’ve noticed that if I resize an animated gif, the resized version is no longer animated. Is there any way to keep the animation?

Hey Gabe,

this is nearly impossible unfortunately as you can see here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=10&t=8808

We might revisit doing this at a later stage, but for now we can’t handle it well.
If you have a good solution to the problem we are happy to implement it.

Sorry for the inconvenience.

Kind regards,
Tim

Hey Tim, from what I’ve read, you can do this with imagemagick using -coalesce
See here: http://www.creativearmory.com/tutorials/resize-animated-gifs-with-php-and-imagemagick

Not sure if that would be too server intensive for you guys..

Tim I also came across this:

http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=17032

The same image magick contributor that previously said it was impossible, is now saying that he added a “-layer TrimBounds” options that you should use instead of repage.

Gabe’s article also seems to be doable. Please investigate which makes more sense.

--fg

I’m getting a lot of requests for animated gif support from my users.
Do you think this is a feature you guys will be able to add within the next few weeks - month or is it just not doable?

Thanks
Gabe

Gabe: We’ll try hard to make that happen!

Tim: You tried a few more options, did anything come out of this?

Yes, seems like I got it to work.

@Gabe: Will let you know here when it’s deployed.

Alright, the feature is deployed.

Gabe can you check it out?

Kind regards,
Tim

Hey Tim, it works great, thanks for getting it deployed so quickly!

My only suggestions now would be some way to keep file size down. I’ve specified a quality of 90 in my template, but this results in a very large file size for animated gifs, like around 3.5mb:
https://transloadit.com/assemblies/view/REDACTED

It would be great if there were a way to specify a different quality for animated gifs.. or more general functionality where you can have template rules that are only executed if a specified meta property of the file is a particular value.. not sure what the bast method would be..

Thanks again!

Gabe

Along those same lines, it would be great if I could generate smaller thumbnails for an animated GIF that aren’t animated.. Would the best way to do that simply be to make all smaller thumbs convert to jpegs, or do you plan on exposing some control over that using template settings?

Thanks
Gabe

Hey Gabe,

yeah we don’t handle that yet in our code. The best would be to force the jpg format on the thumbnails. That should solve this for you.

Regarding executing specific steps under certain conditions (metadata): We are planning to integrate a filter robot that does that. However, it will take quite a while still before that becomes available.

Have you played with the quality setting a bit more? Were you able to tweak it so that your file sizes are reasonable?

Kind regards,
Tim

Your example gif in that assembly is 3.6mb and is 330x200 pixels. You are resizing it to 500x650 with a quality of 85. So I’d expect a similar file size.

Forcing jpg format for thumbnails isn’t really an option, as all sizes of a particular image have to have the same file extension, just because that’s how our code is architected on the backend and it would be a pain to change at this point..

Any chance on you guys adding a template option that allows us to either preserve animated gifs or just use the first frame, like it did previously?

Thanks
Gabe

Hey Gabe,

I will work on this today and let you know when it’s done.

Kind regards,
Tim

Okay it’s ready. Once reviewed it will be deployed - probably tomorrow morning.
Will let you know here, Gabe.

Kind regards,
Tim

Hey Gabe,

the feature got deployed. Check out the new ‘frame’ parameter on the image/resize docs: http://transloadit.com/docs/image-resize

Kind regards,
Tim

Great, thanks a lot Tim. I’m super impressed with your team’s turnaround time for feature requests!

Cheers
Gabe

Thanks. Glad we were able to help!