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...] [> output-file]
gifsicle [options] input-file #frame-selection [> output-file]
gifsicle --batch [options] input-files...

PARAMETERS

-O[level], --optimize[=level]
    Optimize GIF for smaller file size. Levels (1-3) control aggressiveness, with 3 being the most aggressive.

--lossy=N
    Apply lossy compression, sacrificing some image quality for significant file size reduction. N is quality (0-200).

-U, --unoptimize
    Expand optimized GIFs back to an unoptimized form.

-b, --batch
    Process multiple input files, writing each output to a new file named from its input. Requires -o or --output to specify output naming convention (e.g., %b.new.gif).

-i FILE, --input=FILE
    Specify an input file explicitly, useful when filenames start with a dash.

-o FILE, --output=FILE
    Specify the output file name. If omitted, output goes to standard output.

-l[N], --loop[=N]
    Set the animation loop count. N=0 for infinite loop, otherwise N times. Default is 1 (no loop).

-d N, --delay=N
    Set the default delay between frames to N hundredths of a second.

-t N, --transparent=N
    Set the transparent color index to N.

--crop X,Y+W+H
    Crop the image to the specified rectangle (X,Y) with width W and height H.

--resize WxH
    Resize the image to the given width W and height H.

--scale X
    Scale the image by a factor of X (e.g., 0.5 for half size, 2 for double).

--flip-horizontal, --flip-vertical
    Flip the image horizontally or vertically.

--rotate-90, --rotate-180, --rotate-270
    Rotate the image clockwise by 90, 180, or 270 degrees.

--merge
    Combine frames from multiple input GIFs into a single new GIF.

--delete #X-#Y
    Delete a range of frames from the output GIF.

--no-warnings
    Suppress warnings about unusual or problematic GIF features.

--colors N
    Reduce the number of colors in the GIF to a maximum of N.

--interlace, --dont-interlace
    Force interlacing or non-interlacing for the output GIF.

DESCRIPTION

`gifsicle` is a robust command-line utility designed for creating, manipulating, and optimizing Graphics Interchange Format (GIF) images. It provides extensive capabilities for working with both animated and static GIFs, making it an invaluable tool for developers, web designers, and anyone needing to programmatically process GIFs. Users can create animations from sequences of individual image frames, significantly reduce file sizes through various optimization techniques including lossy compression, and perform a wide range of transformations. These transformations include resizing, cropping, rotating, flipping, and merging multiple GIFs. `gifsicle` also allows for advanced control over animation properties such as frame delays, loop counts, and transparency. Its efficiency and scriptability make it a popular choice for automated GIF processing tasks and integration into larger workflows.

CAVEATS

gifsicle is a powerful command-line tool, but it has some considerations. Processing very large GIFs or those with many frames can be memory and CPU intensive. While excellent for batch processing and automated tasks, its command-line interface requires users to learn specific syntax, which might be a barrier for those accustomed to GUI tools. Complex graphical editing features like drawing, layering, or advanced effects are not available; gifsicle focuses on transformations and optimization. Improper use of optimization or unoptimization flags can sometimes lead to an increase in file size instead of a reduction.

<B>OPTIMIZATION LEVELS EXPLAINED</B>

The -O or --optimize option supports different levels of optimization:
-O1 removes duplicate frames and reduces color tables.
-O2 adds smart frame coalescing and disposal methods.
-O3 includes global color table reduction and more aggressive pixel-level optimization, often yielding the smallest files but potentially taking longer to process.

<B>FRAME SELECTION SYNTAX</B>

Frames in a GIF can be selected using a specific syntax. #N refers to the Nth frame (starting from 0). #X-#Y selects a range of frames from X to Y. #-X selects all frames from X to the end. #+X selects X frames starting from the current selection. This allows precise control over which parts of an animation are modified or extracted.

<B>BATCH PROCESSING WITH OUTPUT NAMING</B>

When using the --batch option, `gifsicle` can process multiple input files and generate corresponding output files. The -o or --output option supports format strings for naming the output files. For example, -o %b.new.gif would take an input file like image.gif and produce image.new.gif, where %b represents the base name of the input file.

HISTORY

gifsicle was originally authored by Eddie Kohler, with its first public release appearing around 1997. It quickly gained recognition for its efficiency and comprehensive features in GIF manipulation from the command line. Over the years, it has been actively maintained and improved, becoming a staple utility for web developers, designers, and system administrators who require robust and scriptable control over GIF images. Its enduring popularity stems from its ability to handle complex GIF operations while maintaining a lean and fast execution model.

SEE ALSO

convert(1), ffmpeg(1), identify(1), mogrify(1), gifview(1)

Copied to clipboard