LinuxCommandLibrary

gifsicle

Manipulate and optimize GIF images

TLDR

Optimize a GIF as a new file

$ gifsicle [path/to/input.gif] [[-O|--optimize=]]3 [[-o|--output]] [path/to/output.gif]
copy

Use batch mode (modify each given file in place) and unoptimize a GIF
$ gifsicle [[-b|--batch]] [path/to/input.gif] [[-U|--unoptimize]]
copy

Extract a frame from a GIF
$ gifsicle [path/to/input.gif] '#[0]' > [path/to/first_frame.gif]
copy

Make a GIF animation from selected GIFs
$ gifsicle [*.gif] [[-d|--delay]] [10] [[-l|--loop]] > [path/to/output.gif]
copy

Reduce file size using lossy compression
$ gifsicle [[-b|--batch]] [path/to/input.gif] [[-O|--optimize=]]3 --lossy=[100] [[-k|--colors]] [16] [[-f|--dither]]
copy

Delete the first 10 frames and all frames after frame 20 from a GIF
$ gifsicle [[-b|--batch]] [path/to/input.gif] --delete '#[0-9]' '#[20-]'
copy

Modify all frames by cropping them to a rectangle, changing their scale, flipping them, and rotating them
$ gifsicle [[-b|--batch]] --crop [starting_x],[starting_y]+[rect_width]x[rect_height] --scale [0.25] --flip-horizontal --rotate-[90|180|270] [path/to/input.gif]
copy

SYNOPSIS

gifsicle [options] [input-files...] [-o | --output=output.gif]

PARAMETERS

--help, -h
    Display usage summary and exit

--version, -V
    Print version information

--optimize, -O[1-3]
    Optimize GIF (1=basic, 2=smarter, 3=aggressive)

--no-optimize
    Disable optimization

--careful
    Use safer optimizations (slower)

--unoptimize, -U
    Unoptimize for easier editing

--colors N, -C
    Reduce to at most N colors

--color-method METHOD
    Select color reduction method (e.g., median, adaptive)

--dither
    Apply Floyd-Steinberg dithering

--resize METHOD
    Resize (e.g., 200, 50%, nearest)

--scale SCALE
    Scale by factor (e.g., 0.5)

--crop WxH+X+Y
    Crop to width W height H at offset X,Y

--position XxY
    Reposition image

--rotate {90|180|270}
    Rotate clockwise

--flip-horizontal
    Flip horizontally

--flip-vertical
    Flip vertically

--append FILE
    Append frames from FILE

--insert-before # FILE
    Insert before frame #

--replace # FILE
    Replace frame #

--delete #
    Delete frame(s) by index

--extract #
    Extract frame(s) by index

--loopcount N, --loop=N
    Set animation loop count (0=infinite)

--disposal N
    Set frame disposal method

--delay N
    Set frame delay in 1/100s

--info
    Print image information

--list
    List contents of input GIFs

--batch, -b SCRIPT
    Read commands from SCRIPT

--output FILE, -o FILE
    Write output to FILE

--comment STRING
    Add comment extension

--no-warnings
    Suppress warnings

DESCRIPTION

Gifsicle is a versatile command-line tool for manipulating, creating, and optimizing GIF images, particularly effective for reducing file sizes while preserving visual quality. It excels at processing both static and animated GIFs, supporting operations like color palette reduction, frame insertion/deletion, cropping, resizing, rotation, flipping, and animation controls such as loop counts and frame delays.

Optimization is a core strength, with levels from --optimize=1 (basic cleanup) to --optimize=3 (aggressive reduction via transparent skips, colormap merging, and cleanup passes). Users can batch-process multiple files, script complex edits with --batch, or explode GIFs into frames for external editing. Gifsicle outputs optimized GIFs suitable for web use, often shrinking files by 50-90%.

It handles GIF89a extensions, comments, and application blocks, and provides info/dump modes for analysis. Ideal for developers automating GIF workflows in pipelines.

CAVEATS

Optimizations may slightly alter appearance or lose transparency; test outputs. Only supports GIF input/output. Large animations can be memory-intensive. Not for real-time use.

OPTIMIZATION TIPS

Combine --optimize=3 --careful for best lossless results. Use --lose-transparent for further savings if transparency optional.
--colors 256 preserves full palette.

ANIMATION HANDLING

Frames numbered from 0. Use #- for ranges (e.g., --delete 0-9). --multi for separate output files per input.

HISTORY

Developed by Eddie Kohler starting in 1997 as part of the LC toolkit at Harvard. Maintained actively; version 1.94 released in 2023. Widely adopted for web GIF optimization due to superior compression vs. alternatives.

SEE ALSO

convert(1), identify(1), giftopnm(1), pnmtogif(1)

Copied to clipboard