LinuxCommandLibrary

pnmtopnm

Convert between PNM image formats

TLDR

View documentation for the original command

$ tldr pamtopnm
copy

SYNOPSIS

pnmtopnm [-forceplain | -plain] [-unpredictable] [-nomaxval] [-fixupgamma] [-maxval N] [-gamma N] [-comment string] [-headerrow] [pnmfile]

PARAMETERS

-forceplain
    Forces the output PNM to be in plain (ASCII) format, regardless of the input's format (raw or plain).

-plain
    A synonym for -forceplain.

-unpredictable
    Produces an output with unpredictable values. This option is primarily used for testing Netpbm programs to verify their robustness against unusual input.

-nomaxval
    For PBM images (which always have a maximum pixel value of 1), this option prevents writing the maxval line in the output header, making the header shorter.

-fixupgamma
    Adjusts gamma for plain format images. This helps in maintaining correct gamma representation when converting or processing images, especially with ASCII formats.

-maxval N
    Specifies the maximum pixel value (maxval) for the output PGM or PPM image. Input pixel values are scaled proportionally to this new range. N must be an integer between 1 and 65535.

-gamma N
    Specifies the gamma value for the output image. This affects the brightness and contrast perception of the image. N is a floating-point number.

-comment string
    Adds a comment string to the header of the output PNM file. The comment is typically placed after the magic number and dimensions.

-headerrow
    Adds a header row to the output. This option is generally used for specific processing needs or debugging, providing additional metadata in the output stream.

DESCRIPTION

pnmtopnm is a Netpbm command-line utility designed to convert a Portable Anymap (PNM) file to another PNM file. It serves as a generic wrapper for format-specific tools like pbmtopbm, pgmtopgm, and ppmtoppm, handling binary and ASCII versions of PBM, PGM, and PPM formats. Its primary function is to normalize or modify certain properties of a PNM image, such as changing its maximum pixel value (maxval), converting between plain (ASCII) and raw (binary) formats, or adjusting gamma. It's a fundamental tool for ensuring PNM files are compatible with other Netpbm utilities or for preparing them for specific applications, without altering the visual content of the image.
It reads from standard input if no file is specified and writes to standard output.

CAVEATS

As a Netpbm utility, pnmtopnm strictly operates on PNM formats (PBM, PGM, PPM) and does not convert to or from other image types like JPEG or PNG. While it can adjust certain PNM properties such as maxval or format (plain/raw), it does not alter the actual pixel data or perform general image manipulations like cropping or resizing. Reducing the maxval for PGM/PPM images can lead to a loss of precision or information.

STANDARD INPUT/OUTPUT

If no pnmfile is specified on the command line, pnmtopnm reads the PNM image data from standard input. The converted output is always written to standard output. This behavior allows for seamless piping operations, where the output of one Netpbm command can be directly fed as input to another, facilitating complex image processing workflows.

HISTORY

Part of the Netpbm package, pnmtopnm traces its lineage back to the original Pbmplus tools created by Jef Poskanzer in 1988. As the Netpbm suite evolved, pnmtopnm solidified its role as a fundamental utility for normalizing and manipulating the internal properties of Portable Anymap (PNM) files, without affecting their visual content. It serves as a generic interface that often dispatches to specific format-to-format converters like pbmtopbm, pgmtopgm, and ppmtoppm, making it a core component for maintaining consistency within Netpbm image processing pipelines.

SEE ALSO

pbmtopbm(1), pgmtopgm(1), ppmtoppm(1), netpbm(1), pnm(5), pnmdepth(1), pnmgamma(1)

Copied to clipboard