LinuxCommandLibrary

pnmfile

Determine the type of a PNM image file

TLDR

View documentation for the current command

$ tldr pamfile
copy

SYNOPSIS

pnmfile [-byname|-byvalue|-bywidth|-byheight|-width|-height|-maxval|-format|-type|-color|-pixels|-verbose|-long|-all|-rows|-columns] [filename ...]

PARAMETERS

-byname
    Sorts and prints information about files by their names.

-byvalue
    Sorts and prints information about files by their content value (e.g., a checksum or perceptual hash).

-bywidth
    Sorts and prints information about files by their image width.

-byheight
    Sorts and prints information about files by their image height.

-width
    Prints only the width of the image in pixels.

-height
    Prints only the height of the image in pixels.

-maxval
    Prints only the maximum pixel value (maxval) for the image.

-format
    Prints only the precise Netpbm format name (e.g., PBM, PGM, PPM, PAM).

-type
    Prints a simplified type of the image (e.g., PBM, PGM, PPM, PAM).

-color
    Prints 'color' if the image is color, or 'grayscale' otherwise.

-pixels
    Prints the total number of pixels in the image (width * height).

-verbose
    Prints a detailed summary of all common information for each file, including format, dimensions, maxval, and type.

-long
    Equivalent to -verbose; prints a detailed summary for each file.

-all
    Prints all known information about the image file, including checksums and more obscure details.

-rows
    Prints the height of the image. This option is considered obsolete.

-columns
    Prints the width of the image. This option is considered obsolete.

-version
    Displays the Netpbm package version number.

DESCRIPTION

pnmfile (also known as pnminfo) is a command-line utility from the Netpbm suite designed to report various characteristics of Netpbm image files. It can identify the image format (PBM, PGM, PPM, or PAM), its dimensions (width and height), the maximum pixel value (maxval), and whether the image is color or grayscale. This command is invaluable for scripting image processing workflows, for quickly verifying image attributes, or for simply inspecting file metadata without needing to display the image content. You can request specific pieces of information or a comprehensive summary for one or multiple image files. pnmfile processes files from standard input if no filenames are provided, making it flexible for pipeline use.

CAVEATS

pnmfile is part of the Netpbm suite and primarily works with Netpbm formats (PBM, PGM, PPM, PAM). While it can often infer properties from other image types that Netpbm can implicitly convert (via anytopnm), its core functionality is optimized for its native formats.
If an input file is not a valid Netpbm image, pnmfile will typically report an error and exit with a non-zero status, which is useful for error checking in scripts.
Some options, such as -rows and -columns, are deprecated and their use is discouraged; they may be removed in future Netpbm releases.

DEFAULT OUTPUT

When invoked without specific property options, pnmfile provides a concise default output for each file, typically in the format: filename: <width> x <height> <format> <maxval>. For example, image.ppm: 640 x 480 PPM 255.

EXIT STATUS

pnmfile returns an exit status of 0 if all specified image files are valid Netpbm formats and their information was successfully reported. A non-zero exit status (typically 1) indicates an error, such as an invalid input file, making it suitable for use in shell scripts to check for successful image processing.

HISTORY

pnmfile is a fundamental utility within the Netpbm package, a comprehensive collection of graphics tools for converting and manipulating images. The Netpbm project originated from Jef Poskanzer's Pbmplus toolkit, first released in the late 1980s. As a core component, pnmfile (and its alias pnminfo) has been instrumental from the early days for quickly inspecting the properties of PBM, PGM, and PPM images. The suite has undergone continuous development and maintenance over several decades, evolving into a widely used and reliable command-line tool for basic image processing tasks in Unix-like environments. Its design reflects the Unix philosophy of small, specialized tools that can be chained together.

SEE ALSO

pnminfo(1), pamfile(1), anytopnm(1), identify(1), file(1)

Copied to clipboard