Resize Animated Gif ... and FileSize Problem!

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
islogged
Posts: 5
Joined: 2012-12-29T12:09:59-07:00
Authentication code: 6789

Resize Animated Gif ... and FileSize Problem!

Post by islogged »

Hi,

I have some pb when i resize an animated gif with ImageMagick command line.

Example if i resize this animated gif : http://minus.com/lbhoeRf1376zcx like this :
convert original.gif -coalesce -resize 100x100! output.gif

The work is Ok, but :
original.gif - 140 x 97px - 220 ko

After resize become :
output.gif - 100 x 100px - 826 ko

The output.gif size is more small but the filesize is 4x more big! why?
original.gif = 13 580px² = 220ko
output.gif = 10 000px² = 826ko ... something wrong!

I tried others options of ImageMagick, but the result stay same!

I want an output filesize more small than the original cause i reduce the size of the picture!
Can you help me please ?

Thank you
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize Animated Gif ... and FileSize Problem!

Post by fmw42 »

See optimization options at http://www.imagemagick.org/Usage/anim_opt/ such as -layers OptimizeFrame

See also http://www.imagemagick.org/Usage/anim_mods/#frame_mod as an example of modifying each frame after the coalesce and then optimizing again.
islogged
Posts: 5
Joined: 2012-12-29T12:09:59-07:00
Authentication code: 6789

Re: Resize Animated Gif ... and FileSize Problem!

Post by islogged »

Ok, thank you!

I tried all, but nothing work!!!

Only (-coalesce) with (-resize 100x100!) option work!
With the same problem i explain before (filezise = 4x)

Can you download this GIF file : http://minus.com/lbhoeRf1376zcx and try to do better me ?
Cause for this time i can't solve this pb!

No have an automatic solution to separate all the frames of the GIF, rezise and compress each one, and built again the GIF file with image magick ?

A big thank, if you can help me.
Thank again.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize Animated Gif ... and FileSize Problem!

Post by fmw42 »

I am not really an expert on this, especially frame optimizations. Anthony would be the best to answer this.

I tried the following:

convert ibhoeRf1376zcx.gif -coalesce -resize 100x100 -layers OptimizeFrame test1.gif


The input has a file size of 225 KB and the output is 433 KB. I suspect that the -coalesce fills out your smaller frames, then does the resize. Since it is filled out to 100x100, then the file size of the output could be larger. I am not sure that IM has the best frame optimizations. You might want to pass the output image through and external gif optimizer. See http://www.imagemagick.org/Usage/formats/#gif_non-im

Furthermore, you gif has transparency and it is lost in the coalesce, I think.

I also tried

convert ibhoeRf1376zcx.gif -alpha on -channel rgba -coalesce -resize 100x100 -layers OptimizeFrame -depth 4 -type palettealpha test2.gif

to match your input image depth. This gives about the same size, but the transparency is lost and the colors are changed to be less dark.

I am not sure IM is the best tool for this.

Perhaps Anthony can shed more light.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Resize Animated Gif ... and FileSize Problem!

Post by magick »

Try
  • convert ibhoeRf1376zcx.gif -alpha on -channel rgba -coalesce -resize 100x100 -layers OptimizeFrame -colors 64 test2.gif
or
  • convert ibhoeRf1376zcx.gif -alpha on -channel rgba -coalesce -resize 100x100 -layers OptimizeFrame -treedepth 8 -colors 32 test2.gif
Both returned reasonable results with similar number of bytes compared to the original.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize Animated Gif ... and FileSize Problem!

Post by fmw42 »

I don't know if it makes a difference to the user, but those commands leave the result without its transparency.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Resize Animated Gif ... and FileSize Problem!

Post by anthony »

When you resize an image, any image, animation or otherwise. It will merge pixels, generating LOTS of new colors.

As GIF images usually have a limited color set to begin with (dithered to generate color shades) resizing will merge the dithered colors in detrimental ways. The result is a image with LOTS of colors, that now need to be color reduced to again fit the GIF file format.

Not only that but frame optimization (only overlaying changed areas in the next frame) may not work as well unless specifically pre-dithered using a non-random dither method (like ordered dither), or using less than perfect fuzz factor during the frame optimization.

Basically the GIF will no longer optimize well when resized!

See More information in IM Examples, Animation Modifications, Resizing Animations
http://www.imagemagick.org/Usage/anim_mods/#resize

You may also like to look at the Video to GIF, Optimization Summary
http://www.imagemagick.org/Usage/video/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
islogged
Posts: 5
Joined: 2012-12-29T12:09:59-07:00
Authentication code: 6789

Re: Resize Animated Gif ... and FileSize Problem!

Post by islogged »

Hi and Thanks

I begin to understand the real pb!

if i extract all the frames of my file : http://minus.com/lbhoeRf1376zcx ( 225ko )
convert lbhoeRf1376zcx.gif -coalesce frames\%%04d.gif

The frames\ directory ( 400ko )
It's ok, cause the -coalesce option add/complete informations in each frame !

The real pb with ImageMagick it's when i do :
for %f in ( frames\*.gif ) do ( convert %f -resize 100x100! %f )

Each frame 140x97px reduce to 100x100px
But each frame (1.5ko) grow to 3.5ko !!!

It's mean after reduction the frames\ directory grow 400ko to 850ko
Something Wrong !!!

Another pb, during the resize process, the -depht of some frame change 4 Bits Per Pixel to 8 Bits Per Pixel !!!
I never told to change this parameter ...

I use a batch process, cause i need to convert several Animated Gif
Then i can't not use specific option for each Animated Gif !

I think something wrong with the resize function of ImageMagick cause when i reduce a static Gif resolution with this command, the filesize grow up very fast.

It's illogical !!!

How i can fix this pb ?
Thank you !
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Resize Animated Gif ... and FileSize Problem!

Post by anthony »

If new colors are formed. the old colortable of the GIF is usless and as such gets throwen out. Thus the depth 4 to 8 change (which for GIF is color table size, all colors are still 8 bit in GIF, just the index to teh colors changes size)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply