Home / Alt manpages / pamscale(1)

  • pamscale(1)
  • User command
  • linux

Scale Netpbm Images Predictably with pamscale

You will finish with a repeatable way to resize a Netpbm image, preserve its aspect ratio when that is what you want, and inspect the planned dimensions before writing output. The examples use pamscale from Netpbm 11.5.2, provided here by package netpbm 2:11.05.02-1.1build1.

Allow about fifteen minutes. You need a shell, the Netpbm tools and a PNM, PGM, PPM or PAM input image. The commands below write new files in the current directory. They do not need elevated privileges unless the directory or source file is protected. Do not use sudo just to scale an image.

1. Check the installed command and source image

Confirm which executable will run, then inspect the input dimensions:

$ command -v pamscale
/usr/bin/pamscale
$ pamscale --version
pamscale: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
$ pamfile /path/to/source.ppm
/path/to/source.ppm: PPM raw, 400 by 300

The exact pamfile wording depends on the input format. If the file is not a Netpbm image, convert it first with an appropriate Netpbm converter. Keep the original: pamscale reads standard input or the named file and writes the scaled image to standard output, so redirecting to a new name is the safe pattern.

Checkpoint: identify a source such as /path/to/source.ppm and a destination such as scaled.ppm. If the destination already contains useful data, stop and choose another name. A shell redirection truncates an existing destination before pamscale can warn you.

2. Preview an aspect-preserving fit

Use -xyfit when an image must fit inside a bounding box without distortion. This example plans the largest result that fits within 800 by 600 pixels, but does not create an image:

$ pamscale -xyfit 800 600 -reportonly /path/to/source.ppm
400 300 1.000000 1.000000 400 300

The six fields are input width, input height, horizontal factor, vertical factor, output width and output height. The sample output above is for a 400 by 300 source; your numbers will differ. -reportonly emits one line per input image and sends no scaled image to standard output.

For a source that is larger than the box, the factors will normally be below 1. The fit operation can also leave a smaller source unchanged because enlarging is not required by the bounding box.

Checkpoint: run the report first. Continue only when the final two numbers are acceptable for the consuming application.

3. Write the fitted image to a new file

Repeat the same options without -reportonly and redirect standard output:

$ pamscale -xyfit 800 600 /path/to/source.ppm > fitted.ppm
$ pamfile fitted.ppm
fitted.ppm: PPM raw, 400 by 300

On a source with dimensions that do not already fit, pamfile will show the reduced dimensions. The command preserves the aspect ratio because only the fit box, rather than independent width and height values, determines the scale.

There is no in-place undo. If you chose the wrong destination, remove only that newly created file after checking its path, or restore the destination from your normal backup. Do not run a broad wildcard such as rm *.ppm when recovering from a mistake.

4. Choose exact dimensions or one dimension

Use -width and -height for absolute output dimensions. Supplying both scales the dimensions independently, so it can stretch the image:

$ pamscale -width 800 -height 600 /path/to/source.ppm > exact.ppm
$ pamfile exact.ppm
exact.ppm: PPM raw, 800 by 600

If you supply only one absolute dimension, pamscale calculates the other dimension to preserve the aspect ratio. These are equivalent names for the width and height options: -xsize and -ysize. Prefer the clearer -width and -height forms in new scripts.

Scale factors work differently when only one is supplied. For example, -xscale 0.5 halves the width and leaves the height unchanged. If you want both dimensions to use the same factor, use a single positional factor, such as 0.5, or specify both -xscale and -yscale. The positional form is retained for compatibility; named options make scripts easier to audit.

5. Reduce by a pixel budget

Use -pixels when a downstream limit is a total pixel count rather than a particular width. It scales down to no more than the requested number of pixels and preserves the aspect ratio:

$ pamscale -pixels 1000000 /path/to/source.ppm > preview.ppm
$ pamfile preview.ppm
preview.ppm: PPM raw, 1154 by 866

The example output is illustrative for a suitably large source. Verify your actual result with pamfile. An input already below the limit is copied rather than enlarged. That makes -pixels useful for a maximum-size rule, but not for guaranteeing a particular thumbnail size.

6. Pick the sampling behaviour deliberately

By default, pamscale mixes pixels. This generally gives smoother reductions and can create new intermediate colours. Add -nomix to use discrete sampling instead, which keeps samples from the source palette but can make thin lines uneven or disappear during reduction:

$ pamscale -nomix -width 200 /path/to/source.ppm > palette-safe.ppm
$ pamfile palette-safe.ppm
palette-safe.ppm: PPM raw, 200 by 150

This distinction matters for palette-limited workflows. Mixing may require later colour quantisation before conversion to a restricted format. Discrete sampling is not automatically higher quality; choose it when preserving source sample values is more useful than smooth averaging.

For more control, -filter=function selects resampling, with names such as box, triangle, sinc and lanczos. A filter needs a scale selection as well:

$ pamscale -width 800 -filter=box /path/to/source.ppm > filtered.ppm

Do not combine -linear with -filter: the installed manpage says that -linear is unavailable for resampling and pamscale fails. With the default mixing method, -linear is for data whose samples are already proportional to light intensity. Ordinary PNM and PAM samples are normally gamma-adjusted, so leave it off unless the data format justifies it.

7. Check format and multi-image edge cases

pamscale normally produces the same image type as its input. A PBM input is the exception: it becomes PGM with maxval 255 so pixel mixing has meaningful intermediate values. If you need PBM again, convert the result explicitly with pamditherbw or consider pbmreduce.

The program processes multi-image streams, scaling each image independently on this Netpbm version. That behaviour changed after Netpbm 10.49, so scripts that depend on older installations should check their package version. PAM tuple types outside RGB, grayscale, black-and-white and their alpha variants have no defined general result.

If a command fails, first check that the input is readable, the option has a value, and the output directory is writable. Add -verbose for scaling messages on standard error. Standard output is the image stream, so keep diagnostics separate and do not capture it as though it were text.

Done means

  • You checked the installed pamscale and Netpbm versions.
  • You previewed a size with -reportonly when the dimensions mattered.
  • You wrote to a new destination and verified its dimensions with pamfile.
  • You chose pixel mixing, -nomix or a filter for a stated reason.
  • You accounted for PBM conversion, pixel budgets and multi-image input where relevant.