Replace pnmenlarge with pamenlarge Safely
You will turn an old pnmenlarge command into a current Netpbm workflow: enlarge an image by an integer factor, keep the original file intact, and verify the resulting dimensions. On this machine the installed package is Netpbm 2:11.05.02-1.1build1, which still provides pnmenlarge as the historical command name but documents pamenlarge as its replacement.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes. You need a shell, the netpbm package, and a readable PBM, PGM, PPM or PAM input. The examples write into a working directory and do not need elevated privileges. Do not run the converter as root just because the source image came from another account; fix directory permissions or choose a writable destination instead.
1. Confirm which command is installed
Check both names before changing a script. These are ordinary, read-only commands:
$ command -v pnmenlarge
/usr/bin/pnmenlarge
$ command -v pamenlarge
/usr/bin/pamenlarge
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
The pnmenlarge manual page says that it was replaced in Netpbm 10.25, released in October 2004. The replacement is backward compatible and also handles PAM images. New scripts should name pamenlarge directly so that the intent is clear.
Checkpoint: read the local replacement contract with man pamenlarge. The installed command's --help output only points back to the manual, so the manual is the useful option reference.
2. Choose an integer enlargement
pamenlarge duplicates pixels. A factor of 2 makes both dimensions twice as large and produces four times as many pixels. It does not perform smooth resampling and it cannot use a fractional factor.
The preferred form is the named option:
$ pamenlarge -scale=2 /path/to/input.pgm > enlarged.pgm
Replace both paths with real files. The input filename is optional: if you leave it out, the command reads standard input. A literal - also means standard input. The older positional form remains available for compatibility:
$ pamenlarge 2 /path/to/input.pgm > enlarged.pgm
Keep the option form in new shell scripts. It makes the scale factor easier to spot during review and avoids confusing the number with a filename.
3. Test the pipeline without risking an existing file
Shell redirection with > truncates its destination before the program starts. Choose a new output name for the first run. This command leaves the source untouched:
$ pamenlarge -scale=2 /path/to/input.pgm > /path/to/input-enlarged.pgm
$ printf 'exit status: %s\n' "$?"
exit status: 0
$ file /path/to/input-enlarged.pgm
/path/to/input-enlarged.pgm: Netpbm image data
The wording from file varies by release and image format. The useful checks are a zero exit status and a non-empty output file. If the command fails, do not treat a partially written destination as a valid image.
For a safer replacement of an existing result, write beside it first and move it only after checking it:
$ pamenlarge -scale=2 /path/to/input.pgm > /path/to/result.pgm.new
$ test -s /path/to/result.pgm.new
$ mv -- /path/to/result.pgm.new /path/to/result.pgm
The final mv replaces result.pgm if it already exists. That is a state-changing step: verify the new file before running it, and keep a backup if the old result is difficult to recreate. If the test fails, leave the old result in place and remove the .new file using your normal file-clean-up process.
4. Verify dimensions and format
Do not rely on the filename extension. Ask Netpbm's pamfile to inspect the output when it is installed:
$ pamfile /path/to/input-enlarged.pgm
/path/to/input-enlarged.pgm: PGM raw, 640 by 480 by 255
For a 320 by 240 source and a scale of 2, expect 640 by 480. Exact wording differs between Netpbm releases, but the dimensions should show the factor applied to each axis. A successful exit status only means the pipeline ran; it does not prove that you selected the intended source or factor.
A small self-contained smoke test makes the geometry obvious. It uses a temporary PGM and sends the result to another temporary file:
$ printf 'P2\n2 1\n3\n0 3\n' > /tmp/pnmenlarge-check.pgm
$ pamenlarge -scale=2 /tmp/pnmenlarge-check.pgm > /tmp/pnmenlarge-check-out.pgm
$ pamfile /tmp/pnmenlarge-check-out.pgm
/tmp/pnmenlarge-check-out.pgm: PGM raw, 4 by 2 by 3
The installed command may choose a raw Netpbm representation for the output, even when the input uses the plain text form shown in the test. That is normal: inspect the decoded format and dimensions rather than assuming that the output must preserve the input's encoding.
5. Use separate horizontal and vertical factors when needed
If a square enlargement would distort the layout, provide -xscale and -yscale separately:
$ pamenlarge -xscale=2 -yscale=1 /path/to/input.pgm > /path/to/wide.pgm
$ pamfile /path/to/wide.pgm
/path/to/wide.pgm: PGM raw, 640 by 240 by 255
With only -xscale, the vertical factor is 1. With only -yscale, the horizontal factor is 1. Do not combine -scale with either axis-specific option; the manual rejects that combination. At least one scale option is required unless you use the legacy positional factor.
For a factor of 3 or more, the manual recommends considering a following pnmsmooth step because duplicated pixels can be visually obvious. That changes the look of the image and is not part of the enlargement itself, so inspect the unsmoothed output before adding it.
6. Pick another tool when duplication is the wrong operation
Use pamenlarge when block-preserving integer enlargement is what you want. It is not a general image resizer. For arbitrary factors or reduction, the Netpbm manual points to pamscale, which resamples but is slower. For integer enlargement with a simple smoothing effect, it points to pamstretch. Choose one deliberately rather than compensating for a wrong tool with repeated conversions.
If an input cannot be read, check its path and permissions first:
$ test -r /path/to/input.pgm && printf '%s\n' readable
$ ls -l /path/to/input.pgm
If the output dimensions are wrong, check whether the script used positional and option forms together, or whether one of the axis-specific factors was omitted. If the destination is empty or truncated, restore the previous copy or rerun the command with a new destination. Neither pnmenlarge nor pamenlarge modifies the input image, so the source is the recovery point.
Done means
- You confirmed the installed Netpbm version and identified
pamenlargeas the replacement forpnmenlarge. - Your new command uses a documented integer scale and preserves the source file.
- The output is non-empty, has the expected dimensions, and has been inspected as a Netpbm image.
- You used
-xscaleand-yscaleonly when unequal axes were intentional. - An existing result is replaced only after a separate output has passed its checks.