LinuxCommandLibrary

pamscale

Scale the size of a Netpbm image

TLDR

Scale an image such that the result has the specified dimensions

$ pamscale [[-wid|-width]] [width] [[-h|-height]] [height] [path/to/input.pam] > [path/to/output.pam]
copy

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

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

Scale an image such that it fits into the specified bounding box while preserving its aspect ratio
$ pamscale -xyfit [bbox_width] [bbox_height] [path/to/input.pam] > [path/to/output.pam]
copy

Scale an image such that it completely fills the specified box while preserving its aspect ratio
$ pamscale -xyfill [box_width] [box_height] [path/to/input.pam] > [path/to/output.pam]
copy

SYNOPSIS

pamscale [options] [imagefile]

PARAMETERS

-xscale , -yscale
    Scale the image by the specified horizontal and vertical factors.

-xsize , -ysize
    Resize the image to the exact horizontal and vertical pixel dimensions.

-width , -height
    Aliases for -xsize and -ysize, respectively.

-maxwidth , -maxheight
    Scale the image down only if necessary, to fit within the maximum specified width and height, preserving aspect ratio.

-xfill , -yfill
    Scale the image to fill the specified width or height, maintaining aspect ratio.

-filter
    Specify the interpolation filter algorithm to use (e.g., triangle, gaussian, lanczos3).

-fill=
    Set the color for areas that need to be filled, for example, when stretching to fill a bounding box.

-reduce
    Only reduce the image size; never enlarge it beyond its original dimensions.

-verbose
    Print detailed scaling information and progress to standard error.

-resize
    Use the faster, but generally lower quality, pamstretch algorithm for scaling.

-nomax
    Overrides -maxwidth/-maxheight restrictions when scaling up.

-trueheight
    Interpret -maxheight as the true image height, including any hidden or marginal pixels.

-pixelratio
    Adjust the image's aspect ratio based on non-square pixels.

imagefile
    The input Netpbm image file. If omitted, pamscale reads from standard input.

DESCRIPTION

pamscale is a powerful command-line utility from the Netpbm project, designed for resizing images stored in Netpbm formats (PBM, PGM, PPM, and PAM). It offers precise control over the scaling process, allowing users to resize images by a specific factor, or to exact pixel dimensions, while intelligently preserving the aspect ratio to prevent distortion. A key feature is its support for various interpolation filters, such as triangle, gaussian, and lanczos3, which are crucial for maintaining image quality and minimizing common resizing artifacts like aliasing, blurring, or pixellation. Whether you need to enlarge images for detailed viewing or reduce them for web optimization, pamscale can handle both operations. It also provides flexible options for fitting images within defined maximum dimensions or filling specific areas, making it a versatile tool for automated image preprocessing workflows before further manipulation or display.

CAVEATS

pamscale operates exclusively on Netpbm formats. For images in other formats (like JPEG, PNG, TIFF), they must first be converted to a Netpbm format using appropriate tools (e.g., jpegtopam, pngtopam). The quality of the output image is highly dependent on the chosen -filter and the scaling factor; aggressive scaling with an inappropriate filter can lead to noticeable artifacts. Processing very large images might consume significant memory.

INTERPOLATION FILTERS

pamscale provides a rich set of interpolation filters to control the quality of the resized image. These include common filters like triangle (often a good default for balanced quality), box (nearest neighbor, fastest but lowest quality), gaussian, quadratic, catrom, mitchell, and high-quality options such as lanczos2 and lanczos3, which are known for producing sharp results with minimal aliasing. Selecting the appropriate filter is crucial for achieving desired visual characteristics.

ASPECT RATIO PRESERVATION

By default, or when using options like -maxwidth/-maxheight or -xfill/-yfill where only one dimension is explicitly set, pamscale intelligently preserves the original aspect ratio of the input image. This ensures that images are scaled without distortion, maintaining their correct proportions. This behavior can be overridden by explicitly specifying both -xsize and -ysize, which will force the image to stretch to the exact dimensions provided.

HISTORY

pamscale is a core component of the Netpbm suite of graphics utilities, which evolved from the original Pbmplus package developed in the late 1980s. It significantly improved upon its predecessor, pnmscale, by introducing a much wider range of interpolation filters and more sophisticated scaling algorithms, offering superior image quality and flexibility for modern image processing tasks compared to earlier Netpbm scaling tools.

SEE ALSO

pnmscale(1), pamstretch(1), pamcut(1), pamtopnm(1), pnmtopng(1), jpegtopam(1)

Copied to clipboard