The fastest way to compress an animated GIF from the command line is gifsicle, and the one command that does most of the work is this:
gifsicle -O3 --lossy=80 --colors 128 in.gif -o out.gifThat stacks three levers: maximum optimization (-O3), lossy compression (--lossy=80), and a smaller palette (--colors 128). On a typical screen-recording GIF that routinely cuts the file in half or more. This page covers each lever, then the other GIF jobs that come up around it: inspecting a GIF's frames and delays, changing its speed, setting or stopping its loop, reversing it, and merging several GIFs into one.
Most tutorials show only -O3, which is why people walk away disappointed their GIF "only got 20% smaller." The real win is --lossy, and almost nobody mentions it. And the honest part at the end: if you control how the GIF is made, the bigger win usually is not optimizing the GIF at all.
Install gifsicle
# macOS
brew install gifsicle
# Debian / Ubuntu
sudo apt install gifsicle
# Fedora
sudo dnf install gifsicleThe --lossy flag merged into mainline gifsicle in 1.92 (April 2019); before that it lived in Kornel Lipiński's separate "giflossy" fork. Any version your package manager ships today has it. If a --lossy command errors with "unknown option," check gifsicle --version; an ancient build is the only reason it would.
gifsicle is a tiny, single-purpose tool from Eddie Kohler. It edits GIFs without the heavyweight dependency of ImageMagick, and it is the right tool for anything to do with loop state, frame timing, or size. A few sections below also use ImageMagick (brew install imagemagick or sudo apt install imagemagick). ImageMagick 7 ships the single magick entry point; on version 6 the same commands use the standalone identify and convert binaries with identical flags.
-O3: lossless optimization first
The -O flag reorganizes the GIF so unchanged pixels between frames are not re-stored. It is lossless and never touches image quality:
gifsicle -O3 in.gif -o out.gif-O3 is the most aggressive level: it tries several optimization methods (slower, and the manual is honest that it only "sometimes" beats the lower levels). -O1, which stores only the changed portion of each image, is the default; -O2 adds transparency on top of that. On its own -O3 is modest, often a 10 to 25 percent reduction, which is exactly where the old "gifsicle optimization" guides stopped. It is the floor, not the ceiling.
--lossy: the flag that actually shrinks the file
This is the gem. --lossy lets gifsicle introduce small color artifacts to find longer compressible runs, the same idea JPEG uses for stills:
gifsicle -O3 --lossy=80 in.gif -o out.gifThe number is how much loss to allow. A bare --lossy defaults to 20; higher means smaller files and more visible noise. I find --lossy=80 is the sweet spot for screen recordings and UI demos. For clean line art or text, drop to --lossy=30 or so, because flat color areas show banding sooner. Try a couple of values and eyeball the output; the right number depends on the content.
--colors: shrink the palette
A GIF stores at most 256 colors. Cutting that ceiling drops the per-frame data and stacks with everything above:
gifsicle -O3 --lossy=80 --colors 128 in.gif -o out.gif--colors takes a value between 2 and 256. Screen recordings and flat-design demos rarely need the full 256; 128 or even 64 is usually indistinguishable. Photographic or gradient-heavy GIFs are the exception. Add --dither if banding appears and you want to trade a little file size to hide it.
Resize: the biggest lever of all
Pixel count is the single largest factor in GIF size. Halving the dimensions roughly quarters the data. gifsicle keeps the animation intact while resizing, which is the trap with ImageMagick (a naive convert -resize on a GIF can flatten it to the first frame):
# Constrain width to 480px, height auto to keep aspect ratio
gifsicle --resize-fit-width 480 in.gif -o out-480.gif
# Or scale by a factor
gifsicle --scale 0.5 in.gif -o out-half.gif--resize-fit-width (and --resize-fit-height) only shrink if the GIF is larger than the target, so they never upscale. --scale 0.5 halves both dimensions. If a 1200px-wide GIF goes into a post that renders it at 600px, resizing to 600 first is free quality and a huge size cut.
If the motion can tolerate it, dropping every other frame nearly halves the size too. That trick lives with the timing controls in drop frames instead of lowering the delay.
Batch a whole directory
--batch edits files in place, so you can optimize a folder of GIFs in one pass:
gifsicle --batch -O3 --lossy=80 --colors 128 *.gif--batch rewrites each input file rather than writing to a single -o target. Make a copy first if you want the originals.
One trap when you run gifsicle for size: it does not carry a loop setting through unless you ask. If you do not pass any loop option, the output has no loop extension and plays once, so a forever-looping GIF can silently stop looping. Add --loopcount=forever when you want the loop preserved (details in the loop count section).
Inspect an animated GIF
Before and after optimizing, it helps to see what is inside the file: dimensions, frame count, loop setting and per-frame delays. gifsicle --info (short form -I) is the most complete single view:
gifsicle --info in.gifFor a small animation it prints something like this:
* in.gif 12 images
logical screen 480x270
global color table [256]
loop forever
+ image #0 480x270 transparent 255
disposal asis delay 0.08s
+ image #1 480x270 transparent 255
disposal asis delay 0.08s
...
The first line gives the frame count (12 images). The logical screen line is the canvas size in pixels. loop forever is the loop setting (a finite count shows as a number, and a play-once GIF has no loop line at all). Each + image #N block is one frame, with its own size, offset, transparency index, disposal method, and delay in seconds. Frames in a GIF are often smaller than the canvas and positioned with an offset, which is why per-frame sizes can differ from the logical screen.
Count the frames
For a clean, scriptable frame count, let ImageMagick print one line per frame and count the lines:
magick identify in.gif | wc -lidentify in.gif lists every frame on its own line (in.gif[0] GIF ..., in.gif[1] GIF ...), so wc -l gives the frame count directly. The other approach uses the %n escape, with a catch:
magick identify -format "%n\n" in.gif | head -n 1%n is the number of images in the sequence, and ImageMagick evaluates the format string once per frame. A 12-frame GIF therefore prints 12 twelve times, so take the first line with head -n 1. For a large GIF, add -ping to read only the header and skip decoding every frame: magick identify -ping -format "%n\n" in.gif | head -n 1.
Check whether a GIF is animated
A GIF is animated when it has more than one frame, so the frame count is the whole test:
frames=$(magick identify -format "%n\n" in.gif | head -n 1)
[ "$frames" -gt 1 ] && echo "animated ($frames frames)" || echo "static"A single-frame .gif is just a static image with a GIF extension, and this returns static for it. Keep the head -n 1 in place: without it the %n repetition feeds a multi-line string into the numeric comparison and the test fails.
Extract the first frame as a static image
ImageMagick's bracket syntax selects a single frame by index, counting from zero:
magick "in.gif[0]" first.pngQuote the filename, because the brackets are shell glob characters and an unquoted in.gif[0] can be mangled by the shell before ImageMagick sees it. Any index works: magick "in.gif[5]" frame5.png pulls the sixth frame. This is the standard trick for a static "poster" image to show before a heavy GIF loads.
Total the play time
The duration of one loop is the sum of the per-frame delays. ImageMagick reports each delay in centiseconds with %T, and awk adds them up:
magick identify -format "%T\n" in.gif | awk '{ s += $1 } END { print s/100 " seconds" }'A 12-frame GIF at 8 centiseconds per frame totals 96 centiseconds, so 0.96 seconds per loop. Very small delays are unreliable in practice because browsers clamp them (see the delay floor), so the measured total can be faster than what you actually see on screen.
Change GIF speed
A GIF has no frame rate the way a video does. Each frame stores its own delay, measured in hundredths of a second (centiseconds): a delay of 10 holds each frame for 0.1 second (10 fps), a delay of 4 is 0.04 second (25 fps). Changing a GIF's speed means changing those delays, and gifsicle's --delay overwrites all of them at once with one uniform value:
# Speed it up: 5 centiseconds per frame (20 fps)
gifsicle --delay 5 in.gif -o out.gif
# Slow it down: 20 centiseconds per frame (5 fps)
gifsicle --delay 20 in.gif -o out.gifCheck what a GIF currently uses with gifsicle --info in.gif; each frame line shows its delay, so you can see whether the source has uniform timing or a mix.
The delay floor that catches everyone
You can set --delay 1 and the file will store that 1-centisecond delay, but it will not play at 100 fps in a browser. Modern Chrome and Firefox use a duration of 100 ms (10 fps) for any frame whose delay is 10 ms or less, that is, a delay value of 0 or 1 (a comment in Chromium's GIF decoder spells this out: ad-style frames asking for a near-zero duration get forced to 100 ms). A delay of 2 (20 ms) is the smallest value they honor, so the fastest a GIF reliably plays in a current browser is about 50 fps. Older Internet Explorer and early Firefox used a much higher floor, clamping anything under 100 ms up to 100 ms.
# This does NOT play at ~100 fps. Browsers clamp delay 0 or 1 back to ~10 fps.
gifsicle --delay 1 in.gif -o too-fast.gif
# Delay 2 (20 ms, ~50 fps) is the fastest modern browsers actually honor.
gifsicle --delay 2 in.gif -o fast.gifSo a delay of 0 or 1 makes a slow GIF, not a blazing-fast one. Keep the delay at 2 or higher. This is a property of the GIF format and the renderers, not of gifsicle, so ffmpeg runs into the same wall.
Change speed with ffmpeg (setpts)
If ffmpeg is already in your pipeline, its setpts filter re-times the clip by rewriting each frame's presentation timestamp. A multiplier below 1 speeds it up; above 1 slows it down:
# Double the speed (half the duration)
ffmpeg -i in.gif -vf "setpts=0.5*PTS" out.gif
# Half the speed
ffmpeg -i in.gif -vf "setpts=2.0*PTS" out.gifUnlike gifsicle, which edits the stored delays in place, ffmpeg re-times the stream and re-encodes the GIF, which drops it back to 256 colors. Add a palette pass when quality matters:
ffmpeg -i in.gif -vf "setpts=0.5*PTS,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" out.gifFor a plain speed change with no other editing, gifsicle is the lighter tool: no re-encode, and the palette is untouched.
Drop frames instead of lowering the delay
Changing the delay plays the same frames in less time. Dropping frames keeps the delay but throws away some frames, which shortens the GIF and shrinks the file at the cost of looking choppier. It is the move once a GIF is already at the delay floor, and a cheap size cut for slow UI walkthroughs. There is no single "drop frames" flag; you select the frames to keep and set a delay on the survivors:
# Keep frames 0,2,4,... (every other frame), then re-time the survivors
gifsicle in.gif $(seq -f '#%g' 0 2 98) --delay 4 -o out.gifAdjust the 98 to your last frame index (from gifsicle --info). To hold the original duration rather than speed it up, double the original delay instead. ffmpeg does the same with its fps or select filter if you prefer one pipeline. Rule of thumb: lower the delay first (down to 2), and only drop frames once you have hit that floor and still need it faster or smaller.
Set or stop the GIF loop count
A GIF stores its loop behavior in a small block called the Netscape Application Extension: no extension means play once, a count of 0 means loop forever, and a non-zero count means loop that many times. Changing it does not re-encode the frames, so these commands are instant:
# Loop forever (the usual web default)
gifsicle --loopcount=forever in.gif -o out.gif
# Play through once and stop, no looping
gifsicle --no-loopcount in.gif -o once.gif
# Play once, then repeat 3 more times (4 plays total)
gifsicle --loopcount=3 in.gif -o loop3.gif| You want | Option | What it writes |
|---|---|---|
| Loop forever | --loopcount=forever (or --loopcount=0) | Netscape extension, count 0 |
| Play once and stop | --no-loopcount | No loop extension at all |
| Loop a fixed number of times | --loopcount=N | Netscape extension, count N |
The trap is --loopcount=0. It reads like "zero loops, so play once," but the gifsicle manual is explicit that --loopcount=0 is equivalent to --loopcount=forever. To actually stop a GIF looping you want --no-loopcount, which strips the loop extension entirely. That is also gifsicle's default when you pass no loop option, which is why an optimize pass can quietly turn a looping GIF into a play-once one.
The off-by-one in the count
With --loopcount=N, N is the number of repeats after the first play, not the total number of plays. So --loopcount=3 gives four plays. For exactly three plays, set the count one lower:
# Plays a total of 3 times: once, then 2 repeats
gifsicle --loopcount=2 in.gif -o play-three-times.gifThis is how the Netscape loop count is defined at the format level, so every tool that writes the block inherits it.
Verify the loop you wrote
Do not trust your viewer; trust the file:
gifsicle --info out.gif | grep -i loopA forever-looping GIF shows loop forever, a fixed-count GIF shows the count (loop count 3), and a play-once GIF shows no loop line at all.
Set the loop when creating the GIF with ffmpeg
If you are generating the GIF from a video, ffmpeg's gif muxer has its own -loop option, and its stop value is the inverse idiom of gifsicle's:
| You want | ffmpeg flag |
|---|---|
| Loop forever | -loop 0 (this is the default) |
| Play once, no loop | -loop -1 |
| Loop N times | -loop N |
# Loop forever (ffmpeg's default anyway)
ffmpeg -i in.mp4 -loop 0 out.gif
# Play once and stop
ffmpeg -i in.mp4 -loop -1 out.gif
# Loop 3 times
ffmpeg -i in.mp4 -loop 3 out.gifBoth tools agree that 0 means loop forever. They diverge on switching looping off: gifsicle uses the named --no-loopcount flag, while ffmpeg uses a negative value, -loop -1. ffmpeg's positive -loop N carries the same off-by-one (N repeats after the first play). The -loop flag also has to come before the output filename, or it is silently ignored. If you already have the GIF and only need to change its loop, use gifsicle: running it back through ffmpeg re-encodes every frame and degrades quality unless you redo the palette work.
Reverse an animated GIF
The shortest way to reverse an animated GIF is one ImageMagick command:
magick in.gif -coalesce -reverse out.gifThe part you cannot skip is -coalesce. GIF is a delta format: most encoders store each frame as only the pixels that changed since the previous frame, plus a disposal method. Reverse those diffs without rebuilding the frames and you get the classic corrupted reverse: smears, trails, a background that builds up garbage. -coalesce flattens every frame into a complete standalone image first, which makes reversing safe. 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, re-optimize, loop forever
magick in.gif -coalesce -reverse -layers OptimizePlus -loop 0 out.gifCoalescing makes every frame a full image, so the file grows. -layers OptimizePlus re-derives the inter-frame diffs and 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.
Reverse with ffmpeg or gifsicle
ffmpeg's reverse filter handles GIFs too. Its default GIF encoder dithers hard against a single global palette, so add the palette pass to keep colors clean:
ffmpeg -i in.gif -vf "reverse,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" out.gifffmpeg's docs note that reverse "requires memory to buffer the entire clip, so trimming is suggested," 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 via areverse), see reverse a video with ffmpeg.
gifsicle has no --reverse flag, but its frame selection accepts a descending range:
gifsicle in.gif "#-1-0" -o out.gif#-1-0 selects from the last frame down to the first. Quote it so the shell does not treat # as a comment. gifsicle works on the GIF's own frames rather than coalescing them, so for a heavily delta-optimized source you may still want ImageMagick's -coalesce -reverse -layers OptimizePlus if backward play exposes disposal artifacts.
Make a boomerang (forward then reverse)
A boomerang plays the clip forward, then backward, so it loops with no jump cut. ffmpeg builds it in one pass by concatenating the clip with a reversed copy:
ffmpeg -i in.gif -filter_complex "[0]reverse[r];[0][r]concat,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" boomerang.gif[0]reverse[r] makes a reversed copy, [0][r]concat glues the original in front of it, and the tail is the same palette pass. ImageMagick does it by appending a reversed clone of the coalesced frames:
magick in.gif -coalesce \( -clone -1-0 \) -layers OptimizePlus -loop 0 boomerang.gif( -clone -1-0 ) clones the frames from last to first and appends them. Trim the duplicated turnaround frame (drop the first or last index from the clone range) if the pause at the ends bothers you.
Merge GIFs into one
To play several animated GIFs back to back as one file, concatenate them with gifsicle. Combining inputs into one multi-frame animation is gifsicle's default mode, so the shortest command needs no flag at all:
gifsicle first.gif second.gif > merged.gif
gifsicle --merge first.gif second.gif > merged.gif # explicit default
gifsicle --append first.gif second.gif > merged.gif # append second to firstAll three write every frame of first.gif followed by every frame of second.gif, so the result plays one clip and then the next.
The "only plays the first clip" myth
A persistent claim online says --merge is broken for joining GIFs and you must use --append. The gifsicle manual says otherwise: --merge "combine[s] all GIF inputs into one file with multiple frames" and is "the default mode". What actually happens is that the merged file inherits the loop count of the first input, so if first.gif was set to play once, the combined GIF plays once and stops, which looks like the second clip went missing. Set the loop explicitly instead of switching flags (the loop count section covers the values):
gifsicle --merge --loopcount=forever first.gif second.gif > merged.gif| Flag | What it actually does |
|---|---|
--merge (-m) | The default mode: combine all inputs into one multi-frame animation, played A then B. |
--append | Append the listed GIFs' frames to the input GIF's frames. Same sequential result. |
--loopcount[=N] | Set the output's loop count. This, not the flag choice, fixes a merge that stops after the first clip. |
--multifile | Read as many images as possible from each input; built for scripting an unknown number of files. |
Match sizes and colors before merging
gifsicle appends frames as-is and resizes nothing, so if first.gif is 480 wide and second.gif is 320 wide, the smaller clip sits in a corner of the larger logical screen. Bring both to the same width first. Shrinking the larger clip keeps it sharp:
gifsicle --resize-width 320 first.gif -o first-320.gif
gifsicle --append first-320.gif second.gif > merged.gifUse --resize-width here, not --resize-fit-width: the fit options only ever shrink, so --resize-fit-width 480 would leave a 320-pixel clip at 320. --resize-width 480 second.gif also works if you need the larger size, at the cost of a blurrier upscale.
GIF is also capped at 256 colors per frame, not per file: each frame can carry its own local color table. When two inputs use different palettes whose combined colors do not fit one 256-entry global table, gifsicle still writes the merged file, but prints the warning too many colors, using local colormaps and gives the affected frames local tables, which adds a little size. That is not a failure. If you want one shared global palette (and a slightly smaller file), reduce the colors as the warning itself suggests:
gifsicle --colors 256 --append first.gif second.gif > merged.gifThe 256-per-frame limit belongs to the format, not to gifsicle. If both clips are photographic and banding shows up after a shared palette, keep the local colormaps or move to a video format.
To chain every GIF in a folder, glob them; the shell expands *.gif alphabetically, so name the files in play order (01-intro.gif, 02-body.gif). For a stream of unknown length, --multifile reads from standard input:
gifsicle --colors 256 --append *.gif > merged.gif
cat *.gif | gifsicle --multifile - > merged.gifMerge with ffmpeg, or stack side by side
When the GIFs differ in size or palette enough that gifsicle fights you, ffmpeg's concat filter decodes both, joins the streams, and re-renders a clean GIF with a proper palette. The catch: concat needs every segment at the same resolution and does not convert it for you, so scaling both to the same width is not enough when their aspect ratios differ (a 16:9 clip and a square clip end up 480x270 and 480x480, and ffmpeg refuses to configure the filter). Fit each one inside the same box and pad it to exactly that size first:
ffmpeg -i first.gif -i second.gif -filter_complex \
"[0:v]scale=480:270:force_original_aspect_ratio=decrease,pad=480:270:(ow-iw)/2:(oh-ih)/2,setsar=1[a];[1:v]scale=480:270:force_original_aspect_ratio=decrease,pad=480:270:(ow-iw)/2:(oh-ih)/2,setsar=1[b];[a][b]concat=n=2:v=1[v];[v]split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
merged.gifforce_original_aspect_ratio=decrease shrinks each clip to fit inside 480x270 without distortion, pad centers it on a 480x270 canvas, and setsar=1 keeps the sample aspect ratios identical so concat accepts both. Swap in crop instead of pad if you would rather fill the frame than letterbox. concat=n=2:v=1 joins two video inputs end to end, and the palettegen/paletteuse pair builds a shared 256-color palette so the merge does not introduce banding. If the inputs already match in size, codec, and frame rate, the concat demuxer (ffmpeg -f concat -safe 0 -i files.txt -c copy out.gif) is faster.
If you want two animations playing at the same time next to each other, that is a stack, not a concatenation. hstack needs both inputs at the same height (vstack the same width), so scale first:
ffmpeg -i left.gif -i right.gif -filter_complex \
"[0:v]scale=-1:240[l];[1:v]scale=-1:240[r];[l][r]hstack=inputs=2,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
side-by-side.gifFor side-by-side output, stacking the original source videos and converting to a GIF once at the end beats compositing two already-quantized GIFs, which compounds their palette loss. Either way, run the merged file through gifsicle -O3 --lossy=80 afterwards, since a merge of two GIFs is rarely small.
The honest truth: maybe do not ship a GIF at all
Optimizing a GIF is treating the symptom. The format is from 1987 and is genuinely bad at compressing video; even a heavily optimized GIF is enormous next to a real codec. Two things beat post-optimization outright:
- Generate the GIF well in the first place. If you are converting a video, a quality GIF comes from a per-clip palette, not from squeezing a bad GIF afterward. See convert a video to a GIF with ffmpeg for the two-pass
palettegen/paletteuseflow that produces a smaller, cleaner GIF than any amount of gifsicle on a careless export. - For the web, use a video, not a GIF. A muted, looping, autoplaying MP4 or WebM in a video tag is commonly 5 to 10 times smaller than the equivalent GIF at better quality. GIF only earns its keep where the destination genuinely cannot play video: some chat apps, email, and older platforms that only accept GIF.
So the decision tree is simple. Shipping to a web page you control, encode a video. Stuck with GIF as the delivery format, generate it from a good palette and then run gifsicle -O3 --lossy=80 --colors 128 to claw back the rest.
gifsicle vs ImageMagick for animated GIFs
For static images ImageMagick is the everything-tool, but for animated GIFs gifsicle is the specialist and it usually wins. ImageMagick can optimize and resize GIFs, but it is easy to accidentally collapse the animation to a single frame, and its lossy story is weaker. gifsicle owns compression, timing and loop state. ImageMagick earns its place for scriptable inspection (identify), single-frame extraction, and reversing with -coalesce. If you also need to compress stills, see convert an image to WebP from the command line; for the broader media toolkit, the ffmpeg commands cheat sheet is the reference.
FAQ
gifsicle -O3 --lossy=80 --colors 128 in.gif -o out.gif is the best one-liner for most GIFs. It combines maximum lossless optimization, lossy compression, and a reduced palette. Resize first with --resize-fit-width if the GIF is larger than it needs to be on screen, because pixel count is the biggest factor of all.
Because -O3 alone is lossless and only deduplicates unchanged pixels between frames, which is often a 10 to 25 percent win and no more. The real reductions come from --lossy, --colors, and resizing.
It allows small color artifacts so gifsicle can find longer compressible runs, much like JPEG. A bare --lossy defaults to 20; higher means smaller and noisier. I use --lossy=80 for screen recordings and demos, and something lower like 30 for clean text or line art where banding shows up sooner.
No. gifsicle resizes every frame and keeps the animation intact. That is the reason to prefer it over a naive ImageMagick convert -resize on a GIF, which can flatten the file to a single frame if you are not careful.
Run gifsicle --no-loopcount in.gif -o once.gif. That strips the loop extension so the GIF plays once and stops. Do not use --loopcount=0: per the gifsicle manual that equals --loopcount=forever. When creating the GIF with ffmpeg, the play-once flag is -loop -1.
The loop count is the number of repeats after the first play, not the total. The animation runs once, then loops three more times. For exactly three plays, use --loopcount=2. The GIF format's Netscape loop block defines it this way, so every tool behaves the same.
ImageMagick evaluates a -format string once per frame, so %n is printed once for every frame. Take one line: magick identify -format "%n\n" in.gif | head -n 1. Plain magick identify in.gif | wc -l sidesteps this by counting the one-line-per-frame listing instead.
Browsers enforce a minimum frame delay. Modern Chrome and Firefox treat any frame whose delay is 10 ms or less (a delay value of 0 or 1) as 100 ms, so it plays at about 10 fps. A delay of 2 (20 ms) is the smallest they honor, about 50 fps.
You reversed the frames without coalescing first. GIF stores most frames as diffs against the previous frame, so flipping the order feeds those diffs out of sequence. Run -coalesce before -reverse: magick in.gif -coalesce -reverse out.gif, and add -layers OptimizePlus to bring the size back down.
Both work. --merge is gifsicle's default mode, so gifsicle a.gif b.gif, gifsicle --merge a.gif b.gif, and gifsicle --append a.gif b.gif all produce the same A-then-B animation. A merge that "only plays the first clip" has inherited the first input's loop count; add --loopcount=forever.
It is a warning, not an error: the merged GIF is still written. The source palettes together hold more colors than one 256-entry global table, so gifsicle gives some frames their own local color tables, which costs a little file size. To get one shared palette instead, reduce the colors: gifsicle --colors 256 --append a.gif b.gif > out.gif. If the shared palette bands badly on photographic clips, keep the local colormaps or convert to MP4 or WebM.
If the destination is a web page you control, use a video. A muted, looping, autoplaying MP4 or WebM in a video tag is typically 5 to 10 times smaller than the GIF at better quality. Only optimize a GIF when the target genuinely cannot play video, such as some chat apps and email.
See also
- Convert a video to a GIF with ffmpeg: the two-pass palette flow that makes a small, clean GIF in the first place.
- Convert an image to WebP from the command line: the modern format for stills, far smaller than PNG or JPEG.
- ffmpeg commands cheat sheet: the broader media toolkit for video, audio, and image work in one reference.
Sources
Authoritative references this article was fact-checked against.
- gifsicle manual (official)lcdf.org
- gifsicle man page (Ubuntu)manpages.ubuntu.com
- gifsicle changelog (official)lcdf.org
- FFmpeg filters documentation: palettegen and paletteuse (official)ffmpeg.org
- ffmpeg formats documentation, gif muxer (official)ffmpeg.org
- ffmpeg gif muxer source, libavformat/gif.c (loop AVOption)ffmpeg.org
- ImageMagick format and print escapes (official docs)imagemagick.org
- ImageMagick identify (official docs)imagemagick.org
- ffmpeg setpts filter (official documentation)ffmpeg.org
- ffmpeg concat filter: segments must match resolution (official documentation)ffmpeg.org
- gifsicle source, merge.c: the "too many colors, using local colormaps" warninggithub.com
- The Fastest GIF Does Not Exist: per-browser frame-delay clampingbiphelps.com
- Mozilla bug 125137: minimum frame delay on animated imagesbugzilla.mozilla.org
- ImageMagick Usage: Animation Basics (official)imagemagick.org
- ImageMagick command-line options (official)imagemagick.org
- ffmpeg filters: reverse and areverse (official docs)ffmpeg.org





![Convert SVG to PNG (and PSD to PNG) From the Command Line Convert SVG to PNG from the command line with rsvg-convert, Inkscape, or ImageMagick (size, density, transparency), plus PSD to PNG with the [0] composite.](https://images.techearl.com/convert-svg-to-png-command-line/convert-svg-to-png-command-line-1536.webp?v=2026-11-25T10%3A00%3A00-05%3A00)