pnmpad
Add border (padding) to PNM images
TLDR
Add borders of the specified sizes to the image
Pad the image to the specified size
Pad the width of the image to the specified size, controlling the ratio between right and left padding
Pad the width of the image using the specified color
SYNOPSIS
pnmpad [options] [pnmfile]
PARAMETERS
pnmfile
The input PNM image file. If omitted, pnmpad reads the image data from standard input.
-leftpad N
Adds N pixels of padding to the left side of the image.
-rightpad N
Adds N pixels of padding to the right side of the image.
-toppad N
Adds N pixels of padding to the top side of the image.
-bottompad N
Adds N pixels of padding to the bottom side of the image.
-pad N
Adds N pixels of padding to all four sides (left, right, top, bottom) of the image symmetrically.
-xpad N
Adds N pixels of padding horizontally (evenly split between left and right sides).
-ypad N
Adds N pixels of padding vertically (evenly split between top and bottom sides).
-width W
Sets the total desired output width of the image to W pixels. Padding is added symmetrically to achieve this width.
-height H
Sets the total desired output height of the image to H pixels. Padding is added symmetrically to achieve this height.
-color
Specifies the color of the padding.
-white
Uses white as the padding color. This is a shortcut for -color FFFFFF.
-black
Uses black as the padding color. This is the default behavior and a shortcut for -color 000000.
-transparent
Uses transparent padding. This option only works if the output image format supports an alpha channel (e.g., PAM). The input image must also support alpha or be converted to PAM for this to be effective.
-clip
If the specified output dimensions (using -width or -height) are smaller than the input image, the image will be clipped (cropped) to fit the new dimensions instead of being padded.
-verbose
Prints informational messages about the processing steps being performed by the command.
DESCRIPTION
The pnmpad command adds padding, or borders, to a Portable Anymap (PNM) image. This utility is part of the Netpbm image manipulation toolkit. It allows you to specify the amount of padding to add to each side (left, right, top, bottom) in pixels, or to specify a desired total output width and height, in which case the padding is added symmetrically. The padding can be filled with a specified color (black by default), white, or even made transparent if the output format supports an alpha channel.
This command is useful for adjusting image dimensions without scaling the content, creating frames around images, or preparing images for specific layouts. While primarily designed for padding, pnmpad can also clip an image if the desired output dimensions are smaller than the input and the -clip option is used, effectively performing the inverse operation.
INPUT AND OUTPUT
pnmpad adheres to the standard Unix philosophy of reading from standard input and writing to standard output. By default, it reads a PNM image from standard input. If a pnmfile argument is provided, it reads from that specified file. The resulting padded (or clipped) PNM image is then written to standard output. This design allows it to be easily integrated into shell pipelines with other Netpbm utilities for complex image processing tasks.
INTERACTION OF PADDING OPTIONS
When using multiple padding options, they are applied cumulatively. For instance, if you use -pad N and also -leftpad M, the left side will receive N+M pixels of padding. If -width or -height are used in conjunction with specific side padding options, the fixed side padding is applied first, and then symmetrical padding is added (or clipping is performed if -clip is active) to meet the final desired dimensions.
HISTORY
pnmpad is a fundamental utility within the Netpbm project, a comprehensive suite of graphics programs developed over many years. The Netpbm toolkit, tracing its origins back to the early 1990s as PBMPLUS, provides a foundational set of tools for manipulating various image formats by converting them to and from the intermediate PNM (Portable Anymap) format. pnmpad has been a consistent component, providing a flexible way to adjust image canvases, essential for batch processing and automated image preparation workflows.