LinuxCommandLibrary

giftopnm

Convert GIF images to PNM format

TLDR

Convert a GIF image to a Netpbm image pixel-for-pixel

$ giftopnm [path/to/input.gif] > [path/to/output.pnm]
copy

Display version
$ giftopnm [[-v|-version]]
copy

SYNOPSIS

giftopnm [giffile] [-verbose] [-alphaout=alpha.pbm [-alpha=alpha.pbm]] [-map]

PARAMETERS

-verbose
    Print processing information (frame count, dimensions) to stderr

-alphaout=filename
    Write GIF transparency as PBM alpha mask to filename (no default)

-alpha=filename
    Read external PBM alpha mask from filename to override GIF transparency

-map
    Output a Netpbm mapfile of the GIF colormap to stdout (after image)

DESCRIPTION

giftopnm is a utility from the Netpbm package that reads GIF files (both GIF87a and GIF89a) and converts them to the PNM family: PBM for monochrome, PGM for grayscale, or PPM for color images. It outputs to standard output, making it ideal for piping into other image tools.

The converter handles interlaced GIFs by deinterlacing them and supports multi-frame GIFs (such as animations) by producing a sequence of PNM images, one per frame. Transparency information from GIF89a is preserved and can be extracted as a separate PBM alpha mask file using -alphaout. Users can also supply an external alpha mask via -alpha to override GIF transparency.

A -map option generates a companion mapfile describing the GIF colormap, useful for precise color reproduction. Verbose output aids debugging. No GIF extensions like comments or application blocks are preserved, focusing solely on raster data.

Common use cases include batch conversion in scripts, preparing images for tools lacking GIF support, or integrating into image processing workflows on Unix-like systems.

CAVEATS

Does not preserve GIF comments, extensions, or loop counts; multi-frame outputs must be split with tools like pnmcut or pnmsplit; requires filename argument for -alphaout.

INPUT/OUTPUT

Reads from giffile or stdin; writes PNM to stdout. Use pnmpipe or redirection for files.

MULTI-FRAME HANDLING

Animated GIFs yield concatenated PNM images; split with pnmsplit(1) for individual frames.

HISTORY

Developed by Jef Poskanzer as part of the original PBMPLUS package (1988-1991); integrated into Netpbm (1990s-present) for portable image manipulation on Unix systems.

SEE ALSO

pnmtogif(1), anytopnm(1), ppm(5), pbm(5)

Copied to clipboard