pngtopnm
Convert PNG image to PNM image format
TLDR
View documentation for the current command
SYNOPSIS
pngtopnm [options] [pngfile]
If pngfile is omitted, pngtopnm reads the PNG data from standard input. The converted PNM image is written to standard output.
PARAMETERS
-alpha
Outputs an additional Portable Graymap (PGM) file representing the alpha channel of the PNG image. This allows the transparency information to be processed separately.
-mix
Mixes the alpha channel into the image colors. Transparent pixels are blended with a background color, either specified by the -background option or a default black background, creating a non-transparent output.
-verbose
Prints informative messages to standard error about the conversion process, such as PNG header information and detected features.
-gamma=N
Applies a gamma correction of N to the image. This can be used to adjust the brightness and contrast of the output image, compensating for display or image characteristics.
-text=N
Controls how text chunks (e.g., tEXt, zTXt) embedded in the PNG file are handled. N can be 0 (ignore), 1 (pass to standard error), or 2 (strip from the output).
-transparent=color
Specifies a color to be considered transparent if the PNG file doesn't have an alpha channel, or if -alpha/-mix are not used. color can be a color name (e.g., 'red'), a hexadecimal RGB value (e.g., '#FF0000'), or a comma-separated RGB tuple (e.g., '255,0,0').
-background=color
Specifies the background color used when mixing transparent pixels with the -mix option. This color is used for areas where the PNG image is transparent. The format for color is the same as for -transparent.
DESCRIPTION
pngtopnm is a utility within the Netpbm suite of graphics programs, designed to convert Portable Network Graphics (PNG) image files into the Portable Anymap (PNM) family of formats. The PNM format includes Portable Pixmap (PPM) for color images, Portable Graymap (PGM) for grayscale images, and Portable Bitmap (PBM) for black and white images.
This conversion is crucial for interoperability within the Unix/Linux environment, as the Netpbm tools are known for their simplicity and ability to be easily chained together in pipelines. pngtopnm allows users to take a PNG image and convert it into a format that can then be processed, edited, or converted further by hundreds of other Netpbm programs or standard Unix utilities. It handles various PNG features like alpha channels and gamma correction during conversion.
CAVEATS
While pngtopnm is highly effective for image data conversion, it strips many PNG-specific features such as animations (APNG), embedded profiles (ICC), and extensive metadata beyond basic text chunks. Complex transparency, if not handled by the -alpha or -mix options, will be lost as PNM formats typically do not natively support alpha channels. Therefore, only the raw pixel data and basic color information are preserved.
HISTORY
pngtopnm is a key component of the Netpbm project, which originated from the pbmplus package in the early 1990s. The Netpbm tools were developed to provide a flexible and robust set of command-line utilities for image manipulation, emphasizing a simple 'pipeline' design where programs could feed their output to another program's input. pngtopnm was added as support for the then-emerging PNG format became necessary, fitting seamlessly into the Netpbm philosophy of converting various image formats into and out of the common PNM intermediate representation for further processing.