Home / Alt manpages / pnmscale(1)

  • pnmscale(1)
  • User command
  • linux

Replace pnmscale Safely When Resizing Netpbm Images

You will resize a Netpbm image with the installed pnmscale command, verify the result, and then move new scripts to pamscale. This matters because pnmscale is obsolete: its local manual describes it as replaced by pamscale, while the command remains available for older workflows.

Allow about ten minutes. You need a shell, the netpbm package, a readable PBM, PGM or PPM image, and a writable destination directory. The examples do not need root and do not alter the input. Do not use sudo unless ordinary file permissions genuinely require it.

1. Check which Netpbm you have

Start by confirming the executable and package version. These are read-only checks:

$ command -v pnmscale
/usr/bin/pnmscale
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ pnmscale --version
pnmscale: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
...

The exact package revision is distribution-specific. On the machine used for this guide, pnmscale reports Netpbm 11.5.2 and the package is 2:11.05.02-1.1build1. If the command is missing, install Netpbm through your normal package-management process and rerun this check. Do not infer the installed version from the date on the manual page.

Checkpoint: if command -v prints no path, stop here. A shell alias or a similarly named program is not a substitute for the package command.

2. Resize a copy with the legacy command

The compact legacy form takes one scale factor and an input file. A factor below 1 reduces both dimensions. This example makes a half-size PPM beside the original:

$ pnmscale 0.5 /path/to/input.ppm > /path/to/input-half.ppm

The image is written to standard output, so the shell redirection creates the destination. A factor of 2 would double both dimensions. Keep the source and destination names different until the result has been checked.

For example, an 8 by 4 PPM becomes 4 by 2:

$ file /path/to/input-half.ppm
/path/to/input-half.ppm: Netpbm image data, size = 4 x 2, rawbits, pixmap

Your file wording may differ. The useful facts are the output dimensions and the fact that it is still a Netpbm image. Netpbm may change an ASCII PPM input into a raw PPM output; that is a format representation change, not a failure.

3. Avoid accidental overwrites

Shell redirection with > truncates an existing destination before pnmscale has finished. Use a new temporary name, then replace the old output only after verification:

$ pnmscale 0.5 /path/to/input.ppm > /path/to/input-half.ppm.new
$ file /path/to/input-half.ppm.new
$ mv -- /path/to/input-half.ppm.new /path/to/input-half.ppm

The mv command changes state and can replace an existing destination on the same filesystem. Check the new file first. If conversion fails, leave the original output alone and remove only the incomplete .new file after inspecting it. If you need an explicit recovery point, copy the existing destination before the mv:

$ cp --preserve=all -- /path/to/input-half.ppm /path/to/input-half.ppm.bak

That backup is ordinary user data. Remove it only after the replacement has been opened or passed through the next stage successfully; deletion is irreversible.

4. Use pamscale for new commands

The local pnmscale manual says that pamscale is backward compatible and adds PAM support and other functions. The current Netpbm documentation describes pamscale as the scaling program. Prefer its name in new scripts so the purpose is clear and later options remain available.

To request an exact output width while preserving the aspect ratio, use -width with pamscale:

$ pamscale -width 640 /path/to/input.ppm > /path/to/input-640.ppm
$ file /path/to/input-640.ppm
/path/to/input-640.ppm: Netpbm image data, size = 640 x 320, rawbits, pixmap

For an image whose original ratio is 2:1, the height becomes 320. The command does not edit the source. If you specify both width and height, the dimensions are controlled independently, so the image can be stretched. Use that deliberately rather than assuming the aspect ratio will always be preserved.

The old factor form is also accepted by the installed replacement:

$ pamscale 0.5 /path/to/input.ppm > /path/to/input-half.ppm

Choose one program name per script. Mixing legacy and replacement commands in a pipeline makes troubleshooting harder, especially when one stage writes to standard output and the next stage reads it.

5. Diagnose the common traps

  • No visible output: the image is binary data on standard output. Redirect it to a file; do not paste it into a terminal.
  • The destination is empty or incomplete: inspect the command's exit status immediately, then check the file with file. Keep a known-good source and use a .new destination.
  • The dimensions are not what you expected: a factor scales both axes. Use pamscale -width or explicit dimension options when the target geometry is the requirement.
  • The input cannot be opened: check the path and read permission with ls -l /path/to/input.ppm. Do not solve a typo by running the whole conversion as root.
  • --help only prints a pointer to the manual: that is the installed command's behaviour here. Read man pnmscale or use man pamscale for the replacement's option set.

Neither command is a general-purpose JPEG or PNG converter. Convert those formats to a Netpbm format first with the appropriate Netpbm tool, then scale the resulting PBM, PGM, PPM or PAM stream. Keep intermediate files until the dimensions and visual result are checked.

Done means

  • pnmscale and the Netpbm version were checked before use.
  • The input remained untouched and the output dimensions were verified with file.
  • New scripts use pamscale, the documented replacement.
  • Any replacement of an existing output happened only after a successful check.
  • No elevated privilege was used for ordinary image reading and writing.