Home / Alt manpages / pamenlarge(1)

  • pamenlarge(1)
  • User command
  • linux

Scale Netpbm Images with pamenlarge Without Smoothing Surprises

You will enlarge a Netpbm image by an exact integer factor, write the result to a separate file, and verify its dimensions. pamenlarge duplicates pixels, so the result stays deliberately blocky unless you add a later smoothing step. Allow about ten minutes for a first conversion. You need the netpbm package and a readable PBM, PGM, PPM or PAM image.

1. Check the installed command

Start with read-only checks. This guide was tested with Netpbm 11.5.2, supplied by package version 2:11.05.02-1.1build1 on the test system. Other releases may differ, especially around the newer option syntax.

$ command -v pamenlarge
/usr/bin/pamenlarge
$ pamenlarge --version
pamenlarge: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
... 
$ man pamenlarge

The installed command does not provide a detailed --help screen. Its manual page is the useful interface reference. The current form is pamenlarge -scale=INTEGER FILE; the older positional form is pamenlarge INTEGER FILE.

2. Enlarge both dimensions

Choose a new destination. Shell redirection with > truncates an existing file before pamenlarge starts, so do not point it at an output you may need to recover.

$ pamenlarge -scale=2 /path/to/input.pgm > /path/to/input-2x.pgm
$ file /path/to/input-2x.pgm
/path/to/input-2x.pgm: Netpbm image data, size 2N x 2M, rawbits, greymap

Replace input.pgm and the destination with real paths. The displayed dimensions are placeholders: a source that is N pixels wide and M pixels high becomes 2N by 2M. The output remains the same Netpbm image type as the input. A text PGM can be emitted in Netpbm's raw PGM representation, as in the local test, so do not use the encoding alone to judge whether the image type changed.

Checkpoint: confirm that the destination exists, is non-empty and has the expected width and height. If file is unavailable, inspect the Netpbm header with an installed image utility such as pamfile.

3. Scale only one axis

Use -xscale for horizontal enlargement and -yscale for vertical enlargement. If you specify only one, the other axis has a factor of 1.

$ pamenlarge -xscale=3 /path/to/input.pgm > /path/to/input-wide.pgm
$ file /path/to/input-wide.pgm
/path/to/input-wide.pgm: Netpbm image data, size 3N x M, rawbits, greymap

$ pamenlarge -yscale=2 /path/to/input.pgm > /path/to/input-tall.pgm
$ file /path/to/input-tall.pgm
/path/to/input-tall.pgm: Netpbm image data, size N x 2M, rawbits, greymap

For independent factors, pass both options:

$ pamenlarge -xscale=3 -yscale=2 /path/to/input.pgm > /path/to/input-3x2.pgm

Do not combine -scale with either axis-specific option. The program rejects that combination because it would describe the same dimension twice.

4. Use standard input in a pipeline

The input file is optional. With no file argument, or with -, pamenlarge reads the image from standard input and writes the enlarged image to standard output.

$ cat /path/to/input.pgm | pamenlarge -scale=2 > /path/to/pipeline-output.pgm
$ file /path/to/pipeline-output.pgm
/path/to/pipeline-output.pgm: Netpbm image data, size 2N x 2M, rawbits, greymap

In a longer pipeline, preserve the output redirection at the end or pass it to another Netpbm program. A failure in an earlier command can otherwise leave a partial or misleading destination. For scripts, check the exit status and use a temporary name before replacing a trusted output.

5. Replace an output safely

If you need to update an existing image, convert to a temporary file in the same directory and replace the old file only after verification. This changes state and can still discard the old image, so keep a backup until the new dimensions and appearance are confirmed.

$ cp --preserve=all /path/to/output.pgm /path/to/output.pgm.bak
$ pamenlarge -scale=2 /path/to/input.pgm > /path/to/output.pgm.new
$ file /path/to/output.pgm.new
/path/to/output.pgm.new: Netpbm image data, size 2N x 2M, rawbits, greymap
$ mv /path/to/output.pgm.new /path/to/output.pgm

If conversion fails, the original output.pgm and its backup remain. Remove the incomplete .new file after checking it. Once you have confirmed the replacement, remove the backup manually if you no longer need recovery; that deletion is irreversible. No command in this workflow needs sudo unless your chosen directories deny your normal user access.

6. Diagnose rejected scale factors

Scale factors must be positive integers. A zero or negative value is not a request to reduce an image:

$ pamenlarge -scale=0 /path/to/input.pgm > /tmp/not-created.pgm
pamenlarge: -scale must be positive.  You specified zero
$ printf 'exit status: %s\n' "$?"
exit status: 1

The exact wording can vary, but a non-zero status means the conversion did not complete successfully. Do not treat an output file created by redirection as proof of success: the shell can create or truncate it before the program reports an error. Use a temporary destination for unattended work and remove it only after a successful status and a dimension check.

Remember that this program only accepts integer enlargement factors. Use pamscale for arbitrary enlargement or reduction, including resampling, or pamstretch when you want integer enlargement with a simple smoothing effect. For a factor of 3 or more, the pamenlarge manual suggests considering pnmsmooth because duplicated source pixels remain visible.

7. Choose a practical factor for PBM images

PBM input has an implementation detail that can affect runtime. Netpbm has fast algorithms for PBM scale factors up to 10 and a simpler, slower path for larger factors. If you need a factor of 15, two passes can be faster than one:

$ pamenlarge -scale=5 /path/to/input.pbm | pamenlarge -scale=3 > /path/to/input-15x.pbm
$ file /path/to/input-15x.pbm
/path/to/input-15x.pbm: Netpbm image data, size 15N x 15M, rawbits, bitmap

The order can matter for speed even though both orders produce the same dimensions and pixel values. This is an optimisation for large PBM work, not a requirement for ordinary images. Measure on your own inputs before adding a multi-pass pipeline to a batch job.

Done means

  • pamenlarge is installed and its Netpbm version is known.
  • The input is readable and the chosen factor is a positive integer.
  • The output dimensions match the horizontal and vertical factors.
  • The source remains untouched and important destinations are protected from accidental truncation.
  • You know that pixel duplication preserves hard edges, and have selected a separate smoothing tool when that is wanted.