pnmcut
Cut a rectangle from a portable bitmap
TLDR
View documentation for the current command
SYNOPSIS
pnmcut [-left=N] [-top=N] [-width=N] [-height=N] [pnmfile]
PARAMETERS
-left=N
Specifies the 0-indexed column number for the leftmost edge of the output rectangle. If omitted, defaults to 0 (the leftmost column of the input image).
-top=N
Specifies the 0-indexed row number for the topmost edge of the output rectangle. If omitted, defaults to 0 (the topmost row of the input image).
-width=N
Specifies the desired width of the output rectangle. If omitted, defaults to the width of the input image, effectively cutting to its right edge.
-height=N
Specifies the desired height of the output rectangle. If omitted, defaults to the height of the input image, effectively cutting to its bottom edge.
pnmfile
Optional path to the input PNM image file. If not provided, pnmcut reads the image data from standard input.
DESCRIPTION
pnmcut is a specialized command-line utility from the comprehensive Netpbm toolkit, designed for precise manipulation of portable anymap (PNM) images. It reads a PNM image (PBM, PGM, or PPM format) from standard input or a specified file and extracts a rectangular portion of it. The output is the cropped image, written to standard output.
Users define the desired rectangular region by specifying its top-left corner (x, y coordinates) and its width and height. If any of these parameters are omitted, pnmcut defaults to values that effectively extend the cut region to the image boundaries; for instance, a missing width implies the output should extend to the right edge of the input image. This tool is invaluable for tasks such as isolating specific elements from an image, preparing sub-sections for further processing, or creating image sprites, all within a scriptable and non-interactive environment.
CAVEATS
If the specified cut region extends beyond the input image's boundaries, the output image will be smaller than specified, cutting only up to the actual image edges. If the specified rectangle does not overlap the input image at all, the output will be an empty image (zero width or zero height). All coordinates are 0-indexed; the top-left pixel is at (0,0).
STANDARD INPUT/OUTPUT
pnmcut is designed to work seamlessly within shell pipelines. It reads the PNM image from standard input if no pnmfile argument is provided, and it always writes the resulting cropped PNM image to standard output.
COORDINATE SYSTEM
The coordinate system used by pnmcut (and generally by Netpbm tools) places the origin (0,0) at the top-left corner of the image. Column numbers increase to the right, and row numbers increase downwards.
HISTORY
pnmcut is an integral part of the Netpbm project, a suite of graphics programs that originated from the pbmplus package. Developed to provide fundamental command-line image manipulation capabilities, Netpbm tools, including pnmcut, have been a staple in Unix-like environments for decades, enabling powerful scripting and automation of image processing tasks long before the advent of sophisticated GUI image editors.