pnmscale
Scale PNM image files
TLDR
View documentation for pamscale
SYNOPSIS
pnmscale [options] [pnmfile]
PARAMETERS
-xysize
Scales the image to the exact specified
-xsize
Scales the image to the specified
-ysize
Scales the image to the specified
-scale
Scales the image by the given numerical
-filter
Specifies the interpolation algorithm used for scaling. Common types include nearest (fastest, lowest quality), bilinear (smoother), and bicubic (smoother, higher quality for enlargements). Many other filter types are available.
-maxrgb
When reducing image size, this option uses the maximum of the input pixels' color components instead of the average. This can help preserve color vibrancy in certain scenarios.
-verbose
Prints diagnostic information and details about the scaling process to standard error.
DESCRIPTION
pnmscale is a utility from the Netpbm package designed for scaling graphic images. It reads an image in the PNM (Portable Anymap) format, which includes PBM (Portable Bitmap), PGM (Portable Graymap), or PPM (Portable Pixmap), and outputs a resized version. The command offers flexibility in how images are scaled:
Users can specify an exact output width and/or height, scale by a proportional factor, or fit the image within defined dimensions while preserving its aspect ratio. A key feature of pnmscale is its support for various interpolation algorithms, also known as filters. These range from the fast but lower-quality nearest neighbor, to smoother options like bilinear and bicubic, which are crucial for maintaining image quality during enlargement or significant reduction.
As part of the Netpbm suite, pnmscale is typically used in shell scripts and command-line pipelines, allowing for efficient batch processing and integration with other image manipulation tools.
CAVEATS
pnmscale primarily works with the Netpbm (PNM) image formats. To process other image types (like JPEG, PNG, TIFF), they must first be converted to PNM using other Netpbm tools (e.g., jpegtopnm, pngtopnm) and then converted back if desired.
Higher quality filters (e.g., bicubic) require more computational resources and can be significantly slower, especially for large images. Memory usage can also increase with certain filters and very large images.
PIPELINING AND STANDARD I/O
pnmscale is designed for efficient use in shell pipelines. By default, it reads image data from standard input if no input file is specified, and writes the scaled image to standard output. This facilitates seamless integration with other command-line tools. For example, to resize a JPEG image: jpegtopnm input.jpg | pnmscale -xsize 200 | pnmtojpeg > thumbnail.jpg
PNM FORMATS
The PNM format is a family of simple, ASCII or binary image file formats that includes:
- PBM (Portable Bitmap): Monochrome (black and white) images.
- PGM (Portable Graymap): Grayscale images.
- PPM (Portable Pixmap): Color images.
HISTORY
pnmscale is a core component of the Netpbm suite of graphics utilities, which originated from the Pbmplus package developed by Jef Poskanzer in the late 1980s. Pbmplus was designed around the Unix philosophy of small, single-purpose programs that can be chained together in pipelines. pnmscale perfectly embodies this, focusing solely on image scaling. Over the years, it has been enhanced with a wider array of interpolation algorithms to improve scaling quality. In modern Netpbm distributions, pnmscale is often implemented as a symbolic link to the more general pamscale command, which supports the newer PAM (Portable Anymap Map) format, a superset of PNM, demonstrating its continued relevance and evolution within the Netpbm framework.