# gifsicle — Create, Optimize and Edit Animated GIFs

> Practical guide to gifsicle: create, optimize and edit animated GIFs on the command line — manipulate frames, tweak timing and shrink file size.

Source: https://www.jpkc.com/db/en/cheatsheets/images-media/gifsicle/

<!-- PROSE:intro -->
gifsicle is the Swiss Army knife for GIFs on the command line: it creates, optimizes and edits animated GIFs, extracts or deletes individual frames, adjusts timing and loop behavior, and shrinks file size dramatically with `-O3`, `--colors` and `--lossy`. Keep two things in mind, though: `--lossy` is a lossy operation, and `--batch` (`-b`) edits files in-place, overwriting the original. Make a backup first or write the result to a separate output file.
<!-- PROSE:intro:end -->

## Basic Usage

`gifsicle <input.gif> -o <output.gif>` — Read and write a GIF (basic copy).

```bash
gifsicle animation.gif -o copy.gif
```

`gifsicle -I <input.gif>` — Display information about a GIF (frames, dimensions, colors).

```bash
gifsicle -I animation.gif
```

`gifsicle --info --color-info <input.gif>` — Show detailed info including color table and frame data.

```bash
gifsicle --info --color-info animation.gif
```

`gifsicle --explode <input.gif>` — Extract all frames as individual GIF files.

```bash
gifsicle --explode animation.gif
```

`gifsicle <input.gif> '#0' -o <output.gif>` — Extract a single frame (0-indexed).

```bash
gifsicle animation.gif '#0' -o first-frame.gif
```

## Optimization

`gifsicle -O3 <input.gif> -o <output.gif>` — Maximum optimization (best compression, slowest).

```bash
gifsicle -O3 animation.gif -o optimized.gif
```

`gifsicle -O2 <input.gif> -o <output.gif>` — Standard optimization (good balance of speed and size).

```bash
gifsicle -O2 animation.gif -o optimized.gif
```

`gifsicle -O3 --lossy=<n> <input.gif> -o <output.gif>` — Lossy compression for much smaller files (n = 30-200, higher = smaller).

```bash
gifsicle -O3 --lossy=80 animation.gif -o small.gif
```

`gifsicle --colors <n> <input.gif> -o <output.gif>` — Reduce color palette (2-256 colors).

```bash
gifsicle --colors 64 animation.gif -o reduced.gif
```

`gifsicle --color-method median-cut --colors <n> <input.gif> -o <output.gif>` — Reduce colors using median-cut algorithm (better quality).

```bash
gifsicle --color-method median-cut --colors 128 animation.gif -o reduced.gif
```

`gifsicle -O3 --lossy=80 --colors 128 <input.gif> -o <output.gif>` — Combine lossy compression with color reduction for maximum savings.

```bash
gifsicle -O3 --lossy=80 --colors 128 animation.gif -o tiny.gif
```

## Resize & Crop

`gifsicle --resize <width>x<height> <input.gif> -o <output.gif>` — Resize to exact dimensions.

```bash
gifsicle --resize 320x240 animation.gif -o small.gif
```

`gifsicle --resize-fit <width>x<height> <input.gif> -o <output.gif>` — Resize to fit within dimensions (maintains aspect ratio).

```bash
gifsicle --resize-fit 400x300 animation.gif -o fitted.gif
```

`gifsicle --resize-width <width> <input.gif> -o <output.gif>` — Resize to specific width (auto height).

```bash
gifsicle --resize-width 320 animation.gif -o resized.gif
```

`gifsicle --resize-height <height> <input.gif> -o <output.gif>` — Resize to specific height (auto width).

```bash
gifsicle --resize-height 200 animation.gif -o resized.gif
```

`gifsicle --scale <factor> <input.gif> -o <output.gif>` — Scale by a factor (e.g., 0.5 for half size).

```bash
gifsicle --scale 0.5 animation.gif -o half.gif
```

`gifsicle --crop <x>,<y>+<width>x<height> <input.gif> -o <output.gif>` — Crop a region from the animation.

```bash
gifsicle --crop 10,10+200x150 animation.gif -o cropped.gif
```

`gifsicle --crop-transparency <input.gif> -o <output.gif>` — Remove transparent borders around the image.

```bash
gifsicle --crop-transparency animation.gif -o trimmed.gif
```

## Frame Manipulation

`gifsicle <input.gif> '#0-9' -o <output.gif>` — Extract a range of frames.

```bash
gifsicle animation.gif '#0-9' -o first10.gif
```

`gifsicle <input.gif> '#0' '#2' '#4' -o <output.gif>` — Extract specific frames.

```bash
gifsicle animation.gif '#0' '#5' '#10' -o selected.gif
```

`gifsicle --delete '#<n>' <input.gif> -o <output.gif>` — Delete a specific frame.

```bash
gifsicle --delete '#0' animation.gif -o no-first.gif
```

`gifsicle --delete '#<start>-<end>' <input.gif> -o <output.gif>` — Delete a range of frames.

```bash
gifsicle --delete '#5-10' animation.gif -o shorter.gif
```

`gifsicle <a.gif> <b.gif> -o <output.gif>` — Concatenate two animations.

```bash
gifsicle intro.gif main.gif -o combined.gif
```

`gifsicle --merge <a.gif> <b.gif> -o <output.gif>` — Merge frames from multiple GIFs into one animation.

```bash
gifsicle --merge part1.gif part2.gif part3.gif -o full.gif
```

`gifsicle --reverse <input.gif> -o <output.gif>` — Reverse the frame order (play backwards).

```bash
gifsicle --reverse animation.gif -o reversed.gif
```

## Timing & Looping

`gifsicle --delay <ticks> <input.gif> -o <output.gif>` — Set delay for all frames (in 1/100 second).

```bash
gifsicle --delay 10 animation.gif -o fast.gif
```

`gifsicle '#0' --delay <ticks> '#1-' <input.gif> -o <output.gif>` — Set different delay for first frame vs rest.

```bash
gifsicle animation.gif '#0' --delay 100 '#1-' --delay 5 -o custom.gif
```

`gifsicle --loopcount=<n> <input.gif> -o <output.gif>` — Set loop count (0 = infinite, 1 = play once).

```bash
gifsicle --loopcount=0 animation.gif -o looping.gif
```

`gifsicle --no-loopcount <input.gif> -o <output.gif>` — Remove looping (play once and stop).

```bash
gifsicle --no-loopcount animation.gif -o once.gif
```

## Transform

`gifsicle --rotate-90 <input.gif> -o <output.gif>` — Rotate 90 degrees clockwise.

```bash
gifsicle --rotate-90 animation.gif -o rotated.gif
```

`gifsicle --rotate-180 <input.gif> -o <output.gif>` — Rotate 180 degrees.

```bash
gifsicle --rotate-180 animation.gif -o flipped.gif
```

`gifsicle --rotate-270 <input.gif> -o <output.gif>` — Rotate 270 degrees (90 counter-clockwise).

```bash
gifsicle --rotate-270 animation.gif -o rotated.gif
```

`gifsicle --flip-horizontal <input.gif> -o <output.gif>` — Mirror horizontally.

```bash
gifsicle --flip-horizontal animation.gif -o mirrored.gif
```

`gifsicle --flip-vertical <input.gif> -o <output.gif>` — Mirror vertically.

```bash
gifsicle --flip-vertical animation.gif -o flipped.gif
```

## Common Patterns

`gifsicle -O3 --lossy=80 --resize-fit 480x360 --colors 128 <input.gif> -o <output.gif>` — Optimize for web: resize, reduce colors, lossy compression.

```bash
gifsicle -O3 --lossy=80 --resize-fit 480x360 --colors 128 large.gif -o web.gif
```

`gifsicle -b -O3 *.gif` — Batch optimize all GIFs in-place (-b = replace originals).

```bash
gifsicle -b -O3 *.gif
```

`gifsicle <input.gif> '#0-' '#-2-1' -o <output.gif>` — Create a ping-pong (boomerang) loop.

```bash
gifsicle animation.gif '#0-' '#-2-1' -o boomerang.gif
```

`convert -delay 10 frames/*.png gif:- | gifsicle -O3 --lossy=80 -o <output.gif>` — Create optimized GIF from PNG frames (ImageMagick + gifsicle pipeline).

```bash
convert -delay 10 frames/*.png gif:- | gifsicle -O3 --lossy=80 -o animation.gif
```

<!-- PROSE:outro -->
## Conclusion

gifsicle belongs in every toolbox when animated GIFs need to be small and fast – for everyday work, `-O3`, `--colors` and `--lossy` combined with `--resize-fit` usually do the job. Bear in mind that `--lossy` discards image data irreversibly, and quality degrades visibly at high values. The real footgun is `--batch` (`-b`): it writes the result straight back into the original file, so a bad run cannot be undone. When in doubt, always work with a separate output file (`-o`) or a backup, and check the result before you replace any originals.

## Further Reading

- [gifsicle – official project page (LCDF)](https://www.lcdf.org/gifsicle/) – downloads, documentation and background on the tool
- [gifsicle manual (man page)](https://www.lcdf.org/gifsicle/man.html) – complete reference of all options and frame selectors
<!-- PROSE:outro:end -->

## Related Commands

- [convert](https://www.jpkc.com/db/en/cheatsheets/images-media/convert/) – ImageMagick tool for converting and editing images
- [optipng](https://www.jpkc.com/db/en/cheatsheets/images-media/optipng/) – lossless PNG optimizer
- [pngquant](https://www.jpkc.com/db/en/cheatsheets/images-media/pngquant/) – lossy PNG compression with palette reduction

