LinuxCommandLibrary

pnmscale

Scale PNM image files

TLDR

View documentation for pamscale

$ tldr pamscale
copy

SYNOPSIS

pnmscale [options] [pnmfile]

PARAMETERS

-xysize
    Scales the image to the exact specified and in pixels. This may alter the image's aspect ratio.

-xsize
    Scales the image to the specified in pixels, automatically calculating the height to preserve the aspect ratio.

-ysize
    Scales the image to the specified in pixels, automatically calculating the width to preserve the aspect ratio.

-scale
    Scales the image by the given numerical . For example, a factor of 2.0 doubles the size, while 0.5 halves it.

-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.
While pnmscale specifically refers to these, modern implementations often leverage pamscale, which also supports the PAM format, extending compatibility and functionality.

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.

SEE ALSO

pamscale(1), pnm(5), pam(5), jpegtopnm(1), pnmtojpeg(1), convert(1)

Copied to clipboard