pnmsplit
Split a PNM image into multiple smaller images
TLDR
View documentation for the current command
SYNOPSIS
pnmsplit [-prefix=prefix] [pnmfile]
PARAMETERS
-prefix=prefixname
Specifies filename prefix (default: image); followed by zero-padded 4-digit number and type extension.
DESCRIPTION
pnmsplit is a utility from the Netpbm suite designed to dissect a single PNM (Portable Anymap) file containing multiple images into separate, single-image PNM files. PNM encompasses PBM (portable bitmap), PGM (portable graymap), and PPM (portable pixmap) formats.
The input file must adhere to the Netpbm multi-image convention, where images are delimited by special separator rows—pseudo-header lines beginning with #image or similar markers embedded within the file. pnmsplit identifies these boundaries and extracts each image segment accordingly.
Without the -prefix option, it generates output files named image0001.pbm (or .pgm/.ppm based on the image type), image0002.pbm, and so on, using zero-padded four-digit numbering. The extension matches the detected format of each image. If the input lacks separators, pnmsplit outputs a single file named image0001.*
This tool is invaluable for processing concatenated image streams from sources like scanners or image archives, enabling individual manipulation. It reads from stdin if no file is specified and always writes to disk files, never stdout. Output files are placed in the current directory unless redirected via shell tricks.
CAVEATS
Requires Netpbm multi-image format with proper separators; single-image inputs yield one file only. No stdout output—always creates files. Fails silently on malformed inputs without warnings.
OUTPUT NAMING CONVENTION
Files named prefix%04d.ext, e.g., foo0001.ppm, foo0002.pgm. Extension auto-detected per image.
IMAGE SEPARATORS
Netpbm uses lines like # Netpbm image separator or #image data to delimit images within a stream.
HISTORY
Part of the Netpbm graphics toolkit, originally developed by Jef Poskanzer starting in 1988. pnmsplit added in early 1990s to handle multi-image streams popularized by tools like pnmcat. Maintained in Netpbm releases up to current versions.
SEE ALSO
pnmcat(1), pnmmontage(1), pnm(5), pnmtile(1)


