ppmtoppm
Convert between different PPM image formats
TLDR
Copy a PPM image (i.e. a PBM, PGM or PPM image) from stdin to stdout
Display version
SYNOPSIS
ppmtoppm [-bayer N] [-colors N] [-gamma R] [-gammut] [-invert] [-maxval N] [-nocomments] [-normalize] [-plain] [-quant N] [-truecolor] [ppmfile]
PARAMETERS
-bayer N
Quantizes colors using Bayer dithering, where N specifies the brightness range to use for dithering.
-colors N
Quantizes the image to use exactly N colors. This is an older, less flexible option than -quant.
-gamma R
Applies gamma correction to the image using a gamma value of R.
-gammut
Clips out-of-gamut colors to the sRGB displayable gamut. Equivalent to pnmgamma -gammut.
-invert
Inverts the colors of the image. Equivalent to ppminvert.
-maxval N
Changes the maximum pixel value of the output image to N. Rescales all pixel values accordingly.
-nocomments
Removes any comments present in the input PPM file from the output.
-normalize
Normalizes the colors by stretching the image's contrast. This adjusts the darkest pixel to black and the brightest to white.
-plain
Writes the output PPM file in plain (ASCII) format instead of the default raw (binary) format.
-quant N
Quantizes colors using a more advanced algorithm than -colors. N represents the number of colors to reduce to or a quality parameter.
-truecolor
Ensures the output is a truecolor PPM. If the input is truecolor, this option does nothing; otherwise, it behaves like -maxval 255 if input is non-truecolor.
DESCRIPTION
The ppmtoppm command is a utility from the Netpbm package primarily known for performing a "no operation" on a Portable Pixmap (PPM) image. It takes a PPM image as input and typically produces an identical PPM image as output. Its existence is largely historical, maintaining consistency with commands like pbmtopbm and pgmtopgm, which had significant functions (converting older formats) upon their inception.
While often a pass-through, ppmtoppm can optionally perform various simple transformations. These include color inversion, gamma correction, color quantization, and normalization. However, for most of these transformations, more specialized and general Netpbm programs (such as ppminvert, pnmgamma, or pnmquant) are available and often preferred due to their broader capabilities and flexibility. ppmtoppm can be useful in pipelines where a PPM file needs to be explicitly identified or for very basic, single-step modifications.
CAVEATS
The primary function of ppmtoppm is to perform a no-operation, which can be confusing for new users expecting a significant transformation. For most common image manipulation tasks (color inversion, gamma correction, quantization), more powerful and flexible tools within the Netpbm suite (e.g., ppminvert, pnmgamma, pnmquant) are available and generally recommended over using ppmtoppm with its optional flags. Its continued existence is largely for historical reasons and consistency within the Netpbm family of tools.
COMMON USAGE SCENARIO
While it mostly acts as a pass-through, ppmtoppm can be useful in shell scripts or pipelines where you need to explicitly process a PPM file or apply a very simple, single transformation (like -invert) without invoking a more complex command. For example, cat image.ppm | ppmtoppm -invert > inverted.ppm
HISTORY
ppmtoppm is a part of the Netpbm package, a venerable suite of graphics utilities dating back to the late 1980s and early 1990s. Its initial purpose was largely to provide consistency. When pbmtopbm and pgmtopgm were introduced, they had a functional role in converting older PBM and PGM formats to newer, standardized versions. ppmtoppm was created to complete the trio for the PPM format, even though the PPM format didn't undergo similar significant internal changes requiring a direct conversion tool. Thus, it historically served as a placeholder rather than a primary manipulation tool.