LinuxCommandLibrary

pnmscalefixed

Scale PNM images to fixed dimensions

TLDR

Scale an image such that the result has the specified dimensions

$ pnmscalefixed [[-w|-width]] [width] [[-h|-height]] [height] [path/to/input.pnm] > [path/to/output.pnm]
copy

Scale an image such that the result has the specified width, keeping the aspect ratio
$ pnmscalefixed [[-w|-width]] [width] [path/to/input.pnm] > [path/to/output.pnm]
copy

Scale an image such that its width and height is changed by the specified factors
$ pnmscalefixed [[-xsc|-xscale]] [x_factor] [[-ysc|-yscale]] [y_factor] [path/to/input.pnm] > [path/to/output.pnm]
copy

SYNOPSIS

pnmscalefixed factor [pnmfile]

PARAMETERS

factor
    The mandatory floating-point number representing the scaling factor. For example, 2.0 will double the image size, while 0.5 will halve it. A factor of 1.0 results in no change.

pnmfile
    An optional argument specifying the path to the PNM image file to be scaled. If omitted, pnmscalefixed reads the image data from standard input (stdin).

DESCRIPTION

pnmscalefixed is a command-line utility from the Netpbm package used to resize (scale) Portable Anymap (PNM) images by a fixed, specified factor. Unlike its more general counterpart, pnmscale, pnmscalefixed always employs cubic convolution interpolation to achieve smoother, higher-quality results, particularly when enlarging images. This makes it ideal for situations where image fidelity is paramount. It processes an image from standard input and outputs the scaled image to standard output, making it suitable for use in shell pipelines. The scaling factor is provided as a floating-point number, enabling precise control over the resizing operation. It's a specialized tool focusing on quality-oriented, exact ratio scaling.

CAVEATS

pnmscalefixed exclusively uses cubic convolution interpolation, which can be computationally intensive and slow for very large images or extreme scaling factors.
Output dimensions are rounded to the nearest integer, which might lead to minor discrepancies from exact proportionality in certain edge cases.
It only supports the PNM image formats (PBM, PGM, PPM).

INTERPOLATION METHOD

This command's key characteristic is its exclusive use of cubic convolution for image interpolation. This method calculates new pixel values based on a weighted average of a 4x4 neighborhood of surrounding pixels, resulting in smoother transitions, reduced aliasing, and generally higher visual quality, especially when enlarging images, compared to simpler methods like nearest-neighbor or bilinear interpolation.

INPUT/OUTPUT

pnmscalefixed operates as a filter program: it reads image data from standard input (stdin) and writes the processed, scaled image to standard output (stdout). This design makes it highly flexible and suitable for chaining with other Netpbm utilities or commands in Unix-like shell pipelines.

HISTORY

pnmscalefixed is an integral part of the Netpbm graphics toolkit, which originated as pbmplus by Jef Poskanzer in the late 1980s. It was specifically developed to provide a dedicated tool for high-quality image scaling using cubic convolution interpolation, a method known for superior results compared to simpler algorithms. Its purpose was to offer a specialized, fixed-interpolation scaling option alongside the more versatile pnmscale.

SEE ALSO

pnmscale(1), pamscale(1), pamstretch(1), pnm(5)

Copied to clipboard