Resize an animated GIF using GraphicsMagick

I have an animated image gifwith transparent frames. I need to resize it.

Before resizing, I use the function Magick::coalesceImagesafter resizing the image. I use the function Magick::writeImagesto collect all frames gifback into one image.

The problem is that the resized image file size is larger than the original, since the original animated one gifhas transparent frames, and the new size gifdoes not have transparent frames.

I read about frame optimization at www.imagemagick.org plus I can see at www.graphicsmagick.org gifDisposeMethod .

My question is: how can I make the modified animated image gifuse transparency frames and avoid increasing the image size KBytes?

+3
source share
1 answer

Well, I found a way to go:

When resizing an animated gifuse is Magick::coalesceImages()not the best way ...

Instead, I process according to the percentage, not the absolute size, skipping the call Magick::coalesceImages().

For example, let's say my original animated one gifis 300x300, and I want to resize it to 150x150, I will do the following:

  • Read the image in Magick::Blob
  • Calculate percentage numbers (50% x50% in my demo case).
  • .

, , Magick::coalesceImages(), , .

+3

All Articles