pamtopnm
Convert PAM image files to PNM
TLDR
Convert a PAM image to an equivalent PNM image, i.e. a PBM, PGM or PPM image
Display version
SYNOPSIS
pamtopnm [options] [pamfile]
PARAMETERS
-force-color
Forces the output to be in PPM (Portable PixMap) format, even if the input PAM could be represented as grayscale or black and white. Missing color planes are filled with zeros (black).
-force-grayscale
Forces the output to be in PGM (Portable GreyMap) format. If the input PAM is color, it is converted to grayscale using standard Netpbm luminance conversion.
-force-blackandwhite
Forces the output to be in PBM (Portable BitMap) format. Grayscale or color input PAMs are converted to black and white.
-plain
Outputs the resulting image in the plain (ASCII) Netpbm format rather than the default raw (binary) format. Plain formats are human-readable but larger.
-color-range=maxval
Specifies a new maxval for the output PGM or PPM image. The pixel values from the input PAM are scaled to fit this new maximum value.
-fix-float
(Netpbm 10.95+) Converts PAM images with floating-point samples to integer samples suitable for PBM, PGM, or PPM output. This is necessary for such PAMs, as PBM/PGM/PPM do not support floating-point values.
pamfile
The input PAM image file. If omitted, pamtopnm reads from standard input (stdin).
DESCRIPTION
pamtopnm is a utility from the Netpbm image processing toolkit that converts a Portable Arbitrary Map (PAM) image into one of the simpler Portable BitMap (PBM), Portable GreyMap (PGM), or Portable PixMap (PPM) formats.
The PAM format is a more general Netpbm format designed to handle various kinds of image data, including multiple channels (e.g., alpha, CMYK) and arbitrary depth, which are not directly supported by the older PBM/PGM/PPM formats. pamtopnm acts as a crucial bridge, reducing a generic PAM to a conventional PBM, PGM, or PPM image.
It automatically determines the most appropriate output format based on the input PAM's characteristics: a black and white PAM becomes PBM, a grayscale PAM becomes PGM, and a color PAM becomes PPM. Users can also explicitly force a specific output format using command-line options, for instance, to convert a color PAM to grayscale PGM.
CAVEATS
pamtopnm expects a valid PAM format as input. If the input PAM contains data types or channels that cannot be meaningfully represented in PBM, PGM, or PPM (e.g., specific non-image data), conversion might result in data loss or an invalid output. Explicitly forcing a format (e.g., forcing color to black and white) will result in information loss.
Floating-point PAMs require the -fix-float option for proper conversion to integer-based PBM/PGM/PPM formats.
AUTOMATIC FORMAT DETERMINATION
By default, pamtopnm intelligently determines the most suitable output format: it converts to PBM for 1-bit deep black and white PAMs, to PGM for grayscale PAMs (depth 1 or more), and to PPM for color PAMs (depth 3 or more). This auto-detection makes it very convenient for general use within image processing pipelines.
PIPELINE USAGE
Due to its design, pamtopnm is frequently used in Unix-style pipelines. For example, to convert a PNG image to a grayscale PGM:pngtopam < image.png | pamtopnm -force-grayscale > image.pgm
This allows for powerful and flexible image manipulations by chaining multiple Netpbm utilities.
HISTORY
pamtopnm is an integral part of the Netpbm image processing toolkit. Netpbm originated from Jef Poskanzer's Pbmplus package, developed in the late 1980s. The Portable Arbitrary Map (PAM) format itself was introduced later in Netpbm's development to provide a more flexible and extensible intermediate format, capable of representing more complex image types (like alpha channels, multi-spectral data, or floating-point samples) than the original PBM, PGM, and PPM formats. pamtopnm was created to bridge this gap, allowing PAM images to be converted back into the simpler, widely compatible Netpbm formats for further processing or display by tools that don't yet understand PAM directly.