pnmtopng
Convert PNM image format to PNG
TLDR
Read a PNM image as input and produce a PNG image as output
Display version
SYNOPSIS
pnmtopng [options] [pnmfile]
PARAMETERS
-interlace
Creates an interlaced PNG file using the Adam7 algorithm, which allows a rough image to be displayed quickly and refined over time in web browsers.
-transparent color
Defines a specific color (e.g., 'red', '#RRGGBB', or a pixel value like '0 0 0' for black) in the input image to be transparent in the output PNG. Only one color can be specified.
-alpha alpha_file
Specifies a separate PGM or PBM file to be used as the alpha channel for the output PNG, allowing for per-pixel transparency.
-gamma value
Sets the gamma value for the output PNG image. This can be used for display calibration or to correct image brightness, typically a floating-point number (e.g., 2.2).
-compression N
Sets the compression level for the PNG output. N is an integer from 0 (no compression, fastest) to 9 (maximum compression, slowest). The default is typically 6.
-text "key=value"
Adds a text chunk to the PNG metadata. Multiple -text options can be used to add multiple key-value pairs (e.g., 'Author=John Doe').
-time time_spec
Sets the modification time of the image in the PNG metadata. time_spec can be 'now' or a specific date/time string format (e.g., 'YYYY-MM-DD HH:MM:SS').
-comment "text"
Adds a comment chunk to the PNG metadata, which is typically a short descriptive string.
-force_rgb
Forces the output PNG to be RGB (24-bit) even if the image could otherwise be represented as an indexed color (palette) image.
-force_indexed
Forces the output PNG to be an indexed color image if possible, potentially reducing file size for images with 256 or fewer unique colors.
-verbose
Prints informative messages about the conversion process, such as input/output format detection and compression details, to standard error.
DESCRIPTION
pnmtopng is a versatile command-line utility from the Netpbm suite, designed to convert Portable Anymap (PNM) images into the Portable Network Graphics (PNG) format. PNM encompasses PBM (Portable Bitmap), PGM (Portable Graymap), and PPM (Portable Pixmap) formats. This tool is essential for preparing Netpbm-generated or processed images for web use or other applications that require the widely supported and lossless PNG format. It supports various PNG features like interlacing, transparency, gamma correction, and adjustable compression levels, making it a flexible choice for image conversion tasks. It typically reads PNM data from standard input or a specified file and writes the PNG output to standard output.
CAVEATS
pnmtopng strictly expects a valid PNM (PBM, PGM, or PPM) stream as input; invalid input will result in errors and premature exit. It does not support creating animated PNGs (APNG). When using -transparent, only a single specified color is made transparent, unless an alpha channel file is provided with -alpha for per-pixel transparency.
INPUT/OUTPUT STREAM PROCESSING
By default, pnmtopng reads PNM data from standard input (stdin) and writes the resulting PNG data to standard output (stdout). This design principle is common in Netpbm utilities, enabling powerful command chaining via pipes. For example: anytoppm image.jpg | pnmtopng > image.png
This command converts a JPEG image to PNM, then pipes the PNM data to pnmtopng to convert it to PNG.
SUPPORTED PNG COLOR TYPES
Depending on the input PNM format (PBM, PGM, PPM) and the options used, pnmtopng can generate PNGs with various color types:
- Grayscale (for PGM input)
- Grayscale with alpha (with -alpha)
- Truecolor (RGB for PPM input)
- Truecolor with alpha (RGBA for PPM input with -alpha)
- Indexed color (palette-based for PBM/PGM/PPM with limited colors, often forced by -force_indexed)
HISTORY
pnmtopng is an integral part of the Netpbm project, an open-source package of graphics programs and programming libraries. Netpbm originated from the earlier PBMplus package, developed by Jef Poskanzer in the late 1980s. It has been a standard Unix utility for basic image manipulation and conversion for decades, known for its modular design where tools often work together by piping data, with PNM being the common intermediate format. Its development has focused on robustness and broad compatibility across different image types.