pamcut
Cut rectangular regions from Netpbm images
TLDR
Discard the specified number of columns/rows on each side of the image
Keep only the columns between the specified columns (inclusively)
Fill missing areas with black pixels if the specified rectangle does not entirely lie within the input image
SYNOPSIS
pamcut [options] [input_file]
PARAMETERS
-left X
Specifies the X-coordinate of the left edge of the cut region. The top-left pixel is (0,0).
-top Y
Specifies the Y-coordinate of the top edge of the cut region. The top-left pixel is (0,0).
-width W
Specifies the width of the cut region in pixels.
-height H
Specifies the height of the cut region in pixels.
-right R
Specifies the X-coordinate of the right edge of the cut region. Used as an alternative to -width.
-bottom B
Specifies the Y-coordinate of the bottom edge of the cut region. Used as an alternative to -height.
-xy X Y W H
A convenient shorthand for specifying -left, -top, -width, and -height simultaneously.
-pad
If the specified cut region extends beyond the image boundaries, pad the output with pixels. By default, padding is black.
-force
Suppresses warnings if the cut region extends outside the image boundaries. Useful when combined with -pad.
-fill=color
Specifies the color to use for padding when -pad is active. color can be a color name (e.g., 'red') or hexadecimal RGB (e.g., '#FF0000').
-l X, -t Y, -w W, -h H, -r R, -b B
Shorthand options for -left, -top, -width, -height, -right, and -bottom respectively.
DESCRIPTION
pamcut is a fundamental utility within the Netpbm suite, designed for extracting a specified rectangular sub-region (a 'cut') from an input image or image stream. It supports all Netpbm formats, including PAM, PGM, PPM, and PBM. Users define the desired region by providing its top-left corner coordinates and either its width and height, or its bottom-right corner coordinates. This versatility makes pamcut ideal for tasks such as cropping images, generating thumbnails, or isolating specific graphic elements for subsequent processing. The command offers robust handling for cuts that extend beyond the original image boundaries, with options to pad these areas using a specified color. pamcut's ability to read from standard input and write to standard output makes it highly adaptable for use in command-line pipelines.
CAVEATS
The coordinate system for pamcut is standard: the top-left corner of the image is (0,0). Coordinates increase to the right (X) and down (Y). If a cut region extends beyond the source image's bounds and the -pad option is not used, pamcut will typically issue a warning and clip the output to the valid image area. Using -pad will fill the extended area, by default with black, or with a specified fill color using -fill=color. Ensure input files are in a Netpbm format (PAM, PBM, PGM, PPM).
STANDARD I/O USAGE
pamcut is designed to work seamlessly with Unix pipelines. If no input file is specified, it reads image data from standard input (stdin). The resulting cut image is always written to standard output (stdout), allowing it to be easily piped to other Netpbm utilities or redirected to a file.
DEFAULT BEHAVIOR
If only -left and -top are specified without explicit width/height or right/bottom parameters, pamcut will attempt to cut from the specified top-left coordinate to the end of the image. It is generally best practice to explicitly define the region (e.g., with -width and -height) to avoid unexpected truncation or behavior.
HISTORY
pamcut is a member of the extensive Netpbm package, a collection of graphics programs designed for image manipulation. Netpbm originated in the late 1980s/early 1990s as pbmplus. The pam commands, including pamcut, were introduced as part of the Netpbm project to support the more general PAM (Portable Arbitrary Map) format, which unified and extended the older PBM, PGM, and PPM formats. pamcut effectively supersedes the older pnmcut, offering broader input format compatibility and more robust features for image region extraction.