The shortest way to reverse an animated GIF from the command line is one ImageMagick command:
magick in.gif -coalesce -reverse out.gifThat reads the GIF, rebuilds every frame in full, flips the frame order, and writes a new file that plays backward. The one part you cannot skip is -coalesce, and the rest of this page is mostly about why.
Why -coalesce is not optional
GIF is a delta format. To save space, most encoders store each frame as only the pixels that changed since the previous frame, on top of a disposal method that says what to do with the old frame first. Frame 5 is meaningless without frames 1 through 4 painted underneath it.
Reverse the frame order without rebuilding those frames and you hand the GIF its diffs in the wrong sequence. The result is the classic corrupted reverse: smears, trails, frames that never clear, a background that builds up garbage. The animation is "reversed," but it looks broken.
-coalesce fixes this by flattening every frame into a complete, standalone image first (the full canvas as it would actually appear at that moment). Once each frame is whole, reversing the order is safe. So the rule is simple: coalesce, then reverse. Always in that order.
# Wrong: reverses the diffs, corrupts the animation
magick in.gif -reverse out.gif
# Right: full frames first, then flip the order
magick in.gif -coalesce -reverse out.gifAfter coalescing, every frame is a full image, which makes the file larger. Re-optimize on the way out and set the loop:
magick in.gif -coalesce -reverse -layers OptimizePlus -loop 0 out.gif-layers OptimizePlus re-derives the inter-frame diffs (and frame disposal) so the output is small again, and -loop 0 means loop forever. On ImageMagick 6 the command is convert instead of magick; the flags are identical. Everything here works the same on a modern ImageMagick 7 install.
Reversing with ffmpeg instead
If ffmpeg is already your tool for video, its reverse filter handles GIFs too. The naive form works:
ffmpeg -i in.gif -vf reverse out.gifBut ffmpeg's default GIF encoder builds a single global palette and dithers hard against it, so a colorful source comes out muddy. Run the frames through palettegen and paletteuse to keep the quality:
ffmpeg -i in.gif -vf "reverse,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" out.gifThat reverses the frames, generates an optimal 256-color palette from the reversed stream, and remaps the frames to it. One caveat worth knowing: ffmpeg's docs note that the reverse filter "requires memory to buffer the entire clip, so trimming is suggested." It holds the whole clip in RAM before it can emit the last frame first, so it is fine for a short GIF and a bad idea on a long one. For reversing actual video files (with the audio reversed too via areverse), see reverse a video with ffmpeg.
Reversing with gifsicle
gifsicle has no --reverse flag, but it does not need one: its frame-selection syntax can pull frames in any order, including backward. A descending frame range reverses the animation in a single pass:
gifsicle in.gif "#-1-0" -o out.gifThe #-1-0 selects frames from the last (#-1) down to the first (#0), so the output plays backward. Quote the range in your shell so # is not read as a comment. gifsicle works on the GIF's own frames directly rather than coalescing to a full canvas the way ImageMagick does, so for a heavily delta-optimized source you may still want to round-trip through ImageMagick's -coalesce -reverse -layers OptimizePlus if a backward play exposes disposal artifacts. For a simple GIF, the one-line gifsicle form is the lightest option.
Make a boomerang (forward then reverse)
A boomerang plays the clip forward, then immediately backward, so it loops seamlessly with no jump cut. You build it by concatenating the GIF with its own reverse. ffmpeg does this in one pass:
ffmpeg -i in.gif -filter_complex "[0]reverse[r];[0][r]concat,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" boomerang.gifReading the filter graph: [0]reverse[r] makes a reversed copy, [0][r]concat glues the original in front of the reversed copy, and the split/palettegen/paletteuse tail does the same quality-preserving palette pass as before.
ImageMagick gets there a different way, by appending the coalesced frames to a reversed copy of themselves with a clone:
magick in.gif -coalesce \( -clone -1-0 \) -layers OptimizePlus -loop 0 boomerang.gif( -clone -1-0 ) clones the existing frames in reverse order (last index to first) and appends them, so you end up with forward frames followed by backward frames in a single image list. Trim the duplicated turnaround frame if the pause at the ends bothers you (drop the first or last index from the clone range).
Changing the loop or the speed while you are at it
Reversing is often half of what people actually want. If the reversed GIF should play faster, slower, or loop a set number of times, that is a separate adjustment to the frame delay or loop count, covered in change an animated GIF's speed from the command line. For every GIF and video flag in one place, the ffmpeg command cheat sheet is the reference.
FAQ
See also
- Change an animated GIF's speed from the command line: retime frame delay with ImageMagick or gifsicle once you have the order right.
- Reverse a video with ffmpeg: the same idea for MP4 and friends, including reversing the audio track with
areverse. - The ffmpeg command cheat sheet: convert, crop, trim, and compress video and GIFs from the CLI in one reference.
Sources
Authoritative references this article was fact-checked against.





