LinuxCommandLibrary

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

$ pamtopnm [path/to/image.pam] > [path/to/output.pbm|pgm|ppm]
copy

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

SYNOPSIS

pamtopnm [-ppm|-pgm|-pbm|-pbmalpha] [-plain] [-alphaout={alphaPamFile|-}] [-bgcolor=color] [pamfile]

PARAMETERS

-ppm
    Force PPM (Portable Pixmap) output, even for grayscale or mono images.

-pgm
    Force PGM (Portable Graymap) output, quantizing color to grayscale.

-pbm
    Force PBM (Portable Bitmap) output using Floyd-Steinberg dithering.

-pbmalpha
    Force PBM output with alpha channel dithered to two bit planes (opaque/transparent planes).

-plain
    Produce plain (human-readable ASCII) PNM instead of raw binary.

-alphaout=alphaPamFile|-
    Write alpha channel to separate PAM file (or stdout with '-').

-bgcolor=color
    Composite transparent pixels over specified color (Netpbm quadruplet, e.g., 'white' or '0,0,0,255').

DESCRIPTION

pamtopnm is a command-line tool from the Netpbm graphics suite that reads a Netpbm PAM (Portable AnyMap) image and converts it to a standard PNM (Portable aNyMap) format, such as PPM (color), PGM (grayscale), or PBM (monochrome). PAM is a superset of PNM, supporting advanced features like alpha channels, arbitrary tuple sizes, and color spaces, making pamtopnm essential for pipelines needing PNM compatibility.

By default, it auto-detects the optimal PNM type: PPM for RGB or CMYK images, PGM for grayscale, and PBM for black-and-white with dithering. Output uses maxval 255, scaling if necessary. Alpha transparency can be handled by outputting to a separate PAM file or compositing over a background color.

Forcing formats overrides auto-detection: -ppm for full color, -pbm applies Floyd-Steinberg dithering for bitonal output. Plain (ASCII) PNM is available via -plain. It reads from stdin or a file and writes to stdout, integrating seamlessly with tools like pnmtopng or display. Widely used in batch processing, scripting, and legacy format conversions on Unix-like systems.

DEFAULT BEHAVIOR

Auto-selects PPM/PGM/PBM based on image tuples; scales maxval to 255; writes raw PNM to stdout.

EXAMPLES

pamtopnm image.pam > image.ppm
pamtopnm -pbm -plain grayscale.pam
pamtopnm -alphaout=alpha.pam -bgcolor=white transparent.pam

HISTORY

Developed as part of the Netpbm project by Jef Poskanzer starting in 1988; PAM format introduced in 2000 to extend PNM capabilities. pamtopnm added shortly after for backward compatibility, now maintained by Netpbm community.

SEE ALSO

pnmtopam(1), pamtomp(1), ppmtopam(1), pnm(5), pam(5)

Copied to clipboard