Resizing animated gifs scaling issue

Alec Jacobson

February 27, 2012

weblog/

When trying to resize animated gifs into thumbnails using imagemagick's convert, I noticed that with certain gifs the first frame of the animation would resize correctly but the subsequent frames would remain unscaled or only partially scaled. The command I was using was:
convert input.gif -thumbnail x200 -resize '200x<' -resize 50% -gravity center -crop 100x100+0+0 +repage output.gif
For non-animated gifs, this correctly makes a 100 by 100 thumbnail. For animated gifs where each frame is sufficiently different this creates a animated thumbnail. But for animations whose frames differ only slightly it seems to resize each "difference frame" which may not have the same bounding box. To correct this just add the command "-coalesce" to the beginning of the imagemagick command sequence. Like this:
convert input.gif -coalesce -thumbnail x200 -resize '200x<' -resize 50% -gravity center -crop 100x100+0+0 +repage output.gif