pgmtoppm
Convert PGM image to PPM image
TLDR
Map all greyscale values of the input image to all colors between the two specified colors
Map all greyscale values of the input image to colors according to the specified colormap
SYNOPSIS
pgmtoppm [pgmfile]
DESCRIPTION
pgmtoppm is a utility from the Netpbm graphics toolkit that reads a Portable Graymap (PGM) or Portable Bitmap (PBM) file and converts it to Portable Pixmap (PPM) format.
PGM stores grayscale images with pixel values ranging from 0 (black) to maxval (white), while PBM is a binary subset with pixels 0 or 1. PPM supports full RGB color images.
The conversion replicates the grayscale intensity value equally across the red, green, and blue channels, producing a PPM file that renders as grayscale but can be treated as color. This enables compatibility with tools expecting PPM input, such as image viewers, converters, or editors that do not support PGM directly.
If no input file is specified, pgmtoppm reads from standard input (stdin) and writes PPM to standard output (stdout), making it ideal for pipelines: pgmtoppm input.pgm | ppmtojpeg > out.jpg.
It handles both plain (ASCII) and raw (binary) formats transparently, preserving tuple type, size, and maxval from the input. PBM inputs yield PPM with maxval=1, representing pure black/white.
CAVEATS
Preserves input maxval, so PBM (maxval=1) outputs low-range PPM; use pnmdepth for normalization. No color enhancement or dithering; PPM input unsupported (use pnmtopnm).
EXAMPLES
Convert file:
pgmtoppm input.pgm > output.ppm
Pipeline:
pgmtoppm input.pbm | pnmflip -rotate180 | ppmtojpeg > out.jpg
Normalize maxval first:
pnmdepth 255 input.pgm | pgmtoppm > output.ppm
STANDARDS
Follows Netpbm formats: P1-P5 (PBM/PGM) input yields P3/P6 (PPM) output. Supports all valid maxvals (1-65535).
HISTORY
Developed by Jef Poskanzer as part of the Netpbm suite, first released in 1988. Netpbm originated from the PBMPLUS package and evolved into a standard for portable, low-level image processing on Unix systems, with pgmtoppm unchanged in core functionality across decades.


