LinuxCommandLibrary

pnmquantall

Reduce the number of colors in PNM images

TLDR

Run pnmquant on multiple files with the specified parameters, overwriting the original files

$ pnmquantall [n_colors] [path/to/input1.pnm path/to/input2.pnm ...]
copy

Save the quantised images to files named the same as the input files, but with the specified extension appended
$ pnmquantall [[-e|-ext]] [extension] [n_colors] [path/to/input1.pnm path/to/input2.pnm ...]
copy

SYNOPSIS

pnmquantall [-colors=N] [-mapfile=filename]
[-outfile=format_string] [-verbose]
[-nofloyd | -floyd] [-wu | -mean]
[-extracolors=N] [-posterize=N]
[pnmfile ...]

PARAMETERS

-colors=N
    Target number of colors.
Specifies the maximum number of colors (up to 256) to be
in the output images' colormap. The actual number may be less.

-mapfile=filename
    Output colormap file.
Writes the computed common colormap to the specified file in
PNM format. This can be useful for debugging or reuse.

-outfile=format_string
    Output file naming pattern.
A string containing '%s' (for the input filename) and/or
'%i' (for the sequence number) to specify output filenames.
If omitted, output goes to standard output.

-verbose
    Display progress information.
Prints messages to standard error about the processing
steps and statistics.

-floyd
    Enable Floyd-Steinberg dithering.
This is the default. Uses the Floyd-Steinberg algorithm to
distribute color quantization errors, reducing banding.

-nofloyd | -nodither
    Disable dithering.
Prevents pnmquantall from applying any dithering to
the output images, which can result in sharper but potentially
more banded images.

-wu
    Use Wu's color quantization algorithm.
Selects Wu's algorithm for generating the colormap, which is
generally considered high quality. This is the default.

-mean
    Use mean color quantization algorithm.
Selects a simpler mean-cut algorithm for colormap generation.
Can be faster but potentially lower quality than Wu's.

-extracolors=N
    Add extra colors during quantization.
Adds a specified number of extra colors beyond the -colors
limit for an internal quantization step. This can sometimes
improve quality, though it adds computation.

-posterize=N
    Reduce color levels to N.
Before quantization, reduces the number of distinct intensity
levels for each primary color component to N. Useful for
creating a posterized effect.

pnmfile ...
    Input PNM files.
One or more PNM image files to be processed. If no files
are specified, pnmquantall reads from standard input.

DESCRIPTION

pnmquantall is a Netpbm command-line utility designed for
color quantization of multiple Portable Anymap (PNM)
images simultaneously. Unlike pnmquant, which quantizes
each image individually, pnmquantall analyzes all input
images to compute a single, optimal, common colormap that
represents the colors across the entire set. This is crucial for
applications requiring color consistency, such as creating
animated GIFs or a series of images that need to share a
unified palette. It then converts each input image to use this
generated colormap, effectively reducing the total number of
colors in the sequence while preserving visual fidelity as much
as possible. The default dithering method is Floyd-Steinberg,
which helps to minimize banding artifacts. This tool is
indispensable for preparing image series for constrained color
environments, like older display hardware or specific image
formats.

CAVEATS

pnmquantall can consume significant memory and CPU
time, especially when processing a large number of high-resolution
images. This is due to the need to load all images into memory
(or access them frequently) to build the global colormap.
Care must be taken with the -outfile option to ensure unique
and correctly named output files, particularly when processing
images with similar filenames or complex paths.

INPUT/OUTPUT BEHAVIOR

If no pnmfile arguments are given,
pnmquantall reads a single PNM image from standard input.
If no -outfile is specified, the quantized output images
are written sequentially to standard output. When -outfile
is used, each input image corresponds to a uniquely named
output file. All output images are typically in PPM format.

HISTORY

pnmquantall is an integral part of the Netpbm graphics
conversion toolkit, which evolved from the Pbmplus package
originally developed by Jef Poskanzer in the late 1980s.
It was specifically added to address the challenge of
creating animated GIFs and other sequential image formats
that require a common, consistent color palette across
all frames. Its development allowed for more efficient
and higher-quality batch processing of image sequences
compared to quantizing each image independently.

SEE ALSO

pnmquant(1), gifsicle(1), ppmtogif(1), netpbm(1)

Copied to clipboard