pngtopam
Convert PNG images to PAM format
TLDR
Convert the specified PNG image to a Netpbm image
Create an output image that includes both the main image and transparency mask of the input image
Replace transparent pixels by the specified color
Write tEXt chunks found in the input image to the specified text file
SYNOPSIS
pngtopam [-verbose] [-alphaout={filename|-}] [-alphapam] [-gamma={float}] [-background={color}] [-text={string}] [-time] [-timeislocal] [-transparent={color}] [-usetrans] [pngfile]
PARAMETERS
-verbose
Prints detailed debugging information to standard error during processing.
-alphaout={filename|-}
Extracts the PNG's alpha channel into a separate PGM (Portable Graymap) file. If '-' is specified as the filename, the PGM output goes to standard output, causing the main PAM output to be redirected to standard error.
-alphapam
Extracts the alpha channel as a PAM image instead of the default PGM format.
-gamma={float}
Overrides any gamma value specified in the PNG file, allowing for custom gamma correction. A value of 0.0 disables gamma correction.
-background={color}
Composites the image against a specified background color. The color can be an RGB hex string (e.g., #RRGGBB) or a recognized color name.
-text={string}
Outputs any textual chunks embedded within the PNG file as messages to standard error.
-time
Prints time-related information (e.g., last modification time) from the PNG file to standard error.
-timeislocal
Interprets any time information found in the PNG file as local time, rather than Coordinated Universal Time (UTC).
-transparent={color}
Treats the specified color as transparent, applying transparency to pixels matching this color.
-usetrans
Uses the transparent color defined within the PNG file itself (if present) for transparency processing.
pngfile
The path to the input PNG image file. If omitted, pngtopam reads from standard input.
DESCRIPTION
pngtopam is a command-line utility from the Netpbm suite designed to convert Portable Network Graphics (PNG) image files into the Portable Arbitrary Map (PAM) format.
PAM is Netpbm's most general image format, capable of representing images with any number of samples per pixel, including color, grayscale, and alpha channels. This tool effectively handles all PNG color types and bit depths, making it a versatile converter. By default, it reads a PNG file from standard input if no filename is provided and writes the resulting PAM image to standard output.
For PNGs without an alpha channel, pngtopam outputs a PGM (grayscale) or PPM (color) image, which are simpler Netpbm formats. The command leverages the libpng library for PNG decoding.
CAVEATS
When using the -alphaout - option to send the alpha channel to standard output, the primary PAM image output is unexpectedly redirected to standard error. This behavior can be confusing and requires careful handling in scripts.
The pngtopam command primarily focuses on converting the raw pixel data and alpha information. While it uses libpng, which may process sRGB or iCCP color profiles, pngtopam itself does not offer explicit options to control or manipulate these color management aspects directly, beyond gamma correction.
OUTPUT FORMAT DETAIL
pngtopam's default output is the PAM format, which is the most general Netpbm format. If the input PNG does not have an alpha channel, the output PAM image will effectively be a PGM (for grayscale) or PPM (for color) image, which are simpler, more specialized Netpbm formats. The output format is always written to standard output unless specified otherwise (e.g., with -alphaout -).
STANDARD INPUT/OUTPUT USAGE
The command is designed to work seamlessly within Unix pipelines. If no pngfile argument is provided, pngtopam reads the PNG image data from standard input (stdin). The resulting PAM image is then written to standard output (stdout), making it easy to chain with other Netpbm utilities or external commands.
HISTORY
pngtopam is an integral part of the Netpbm image processing toolkit, which itself has a long and rich history. The Netpbm project is a direct descendant of the original PBMplus package developed by Jef Poskanzer in the late 1980s. PBMplus aimed to provide a set of simple, composable tools for image manipulation based on the Portable BitMap (PBM), Portable GrayMap (PGM), and Portable PixMap (PPM) formats.
As image formats evolved, Netpbm adapted by incorporating support for newer formats like PNG and introducing more generalized formats like PAM. pngtopam was developed to bridge PNG images with the Netpbm ecosystem, allowing PNGs to be processed and transformed using the vast array of Netpbm utilities by first converting them into a Netpbm format. Its development closely tracks the evolution and adoption of the PNG standard and the ongoing maintenance of the Netpbm project.