How to Resize an Animated GIF with ImageMagick?
To resize an animated GIF without losing its animation or ruining its
optimization using ImageMagick, you must use the -coalesce
command before resizing and the -layers Optimize command
afterward. This process unpacks the individual frames, scales them
uniformly, and then re-compresses them to keep the file size manageable.
Failure to include these specific steps will result in a distorted,
broken, or completely static image.
The Core Command
The standard syntax for resizing an animated GIF properly requires a specific sequence of operations. You can run the following command in your terminal:
convert input.gif -coalesce -resize 500x500 output.gifIf you want to ensure the file size remains small and the animation layers are re-optimized after the resize, use this expanded version:
convert input.gif -coalesce -resize 500x500 -layers Optimize output.gifBreaking Down the Code
convert input.gif: This calls ImageMagick and loads your original animated GIF.-coalesce: Animated GIFs often save space by only recording the pixels that change from frame to frame. This flag merges those differences back into full, individual frames so they can be resized accurately. Without this, the resized GIF will look like a glitchy mess of overlapping frames.-resize 500x500: This defines your new target dimensions. ImageMagick will maintain the original aspect ratio by default, fitting the image within a 500x500 pixel bounding box.-layers Optimize: This flag strips out identical pixel data between consecutive frames again, rebuilding the GIF optimization to reduce the final file size.output.gif: This is the filename for your newly resized animation.
Resizing by Percentage
If you prefer to scale the image by a specific percentage rather than defining exact pixel dimensions, you can replace the pixel values with a percentage flag:
convert input.gif -coalesce -resize 50% -layers Optimize output.gifUsing this method ensures that every frame is scaled down by exactly half, preserving both the original proportions and the animation timeline flawlessly.