LinuxCommandLibrary

pnmsplit

Split a PNM image into multiple smaller images

TLDR

View documentation for the current command

$ tldr pamsplit
copy

SYNOPSIS

pnmsplit [-basefile basename] [-digits N] [-ext extension] [-outfilepattern pattern]

PARAMETERS

-basefile basename
    Specifies the base string for output filenames. For example, with -basefile frame, files will be named frame00000.pnm, frame00001.pnm, etc. The default is image.

-digits N
    Sets the number of digits N to use for the sequential part of the filename. For instance, -digits 3 would result in names like image000.pnm, image001.pnm, etc. The default is 5.

-ext extension
    Defines the filename extension for the output files. For example, -ext .png would use .png instead of .pnm. The default is .pnm.

-outfilepattern pattern
    Provides a printf-style format string for generating output filenames. This option overrides -basefile, -digits, and -ext. The pattern must contain a %d (or similar integer specifier like %05d) for the sequence number. Example: -outfilepattern "series_%03d.pgm".

DESCRIPTION

pnmsplit is a utility that reads a stream of one or more portable anymap images (PBM, PGM, or PPM) from standard input and writes each individual image to a separate file. This command is particularly useful for extracting frames from animations, multi-page documents, or any concatenated PNM stream. By default, it generates output filenames sequentially, such as image00000.pnm, image00001.pnm, and so on, using 5 digits for the sequence number and the .pnm extension. Users can customize the base filename prefix, the number of digits for sequencing, and the file extension. For advanced control, a printf-style output filename pattern can be specified, overriding the default naming conventions. It consistently uses the Portable Anymap formats for output files, which can be any of PBM, PGM, or PPM depending on the input image content.

CAVEATS

When using -digits N, ensure N is sufficient to accommodate the expected number of images; an insufficient number of digits could lead to non-unique filenames if the sequence number overflows the specified digit count.

The default output extension is .pnm, even if the internal image format is specifically PBM, PGM, or PPM. Consider using -ext or -outfilepattern for more specific extensions if desired.

INPUT AND OUTPUT

pnmsplit reads image data from standard input (stdin). The output images are written to individual files in the current working directory, or to paths specified within the -outfilepattern.

USAGE EXAMPLE

To split a multi-image GIF animation (after converting it to PNM) into separate PPM files named frame_000.ppm, frame_001.ppm, etc.:

giftoppm < animation.gif | pnmsplit -outfilepattern "frame_%03d.ppm"

This demonstrates its common use in a pipeline with other Netpbm tools.

HISTORY

pnmsplit is a core utility within the Netpbm package, a long-established open-source toolkit for graphics manipulation. Its design reflects the Unix philosophy of small, specialized tools that can be chained together. It has been a stable part of the Netpbm suite for many years, providing a fundamental capability for image stream processing.

SEE ALSO

pnm(5), pnmcat(1), pnmindex(1), netpbm(1)

Copied to clipboard