Home / Alt manpages / pbmpscale(1)

  • pbmpscale(1)
  • User command
  • linux

Enlarge a PBM Bitmap with Edge Smoothing Using pbmpscale

You will enlarge a black-and-white PBM image by a whole-number factor and save a new PBM file with predictable dimensions. The installed command is Netpbm 11.5.2, from package version 2:11.05.02-1.1build1. Allow about ten minutes. You need a shell, a readable PBM input file, and enough space for the larger output. No step in this guide needs elevated privileges.

1. Check the installed command

Confirm which executable will run and read its short usage message:

$ command -v pbmpscale
/usr/bin/pbmpscale
$ pbmpscale
pbmpscale: Use 'man pbmpscale' for help.
pbmpscale: You must specify the scale factor as an argument

The command takes a scale factor first, followed by an optional PBM filename:

pbmpscale N [pbmfile]

There are no pbmpscale-specific switches. Netpbm common options may also be accepted, but do not add one unless you have checked the common-options documentation for the installed Netpbm release.

Checkpoint

The first argument is the factor, not the input path. A command such as pbmpscale image.pbm 2 has the arguments in the wrong order.

2. Enlarge an existing PBM file

Use a new destination name so the original remains available for comparison or recovery:

$ pbmpscale 2 /path/to/input.pbm > input-2x.pbm

2 asks for a two-times enlargement in both directions. The program reads a PBM image, replicates pixels, and adds smoothing around corners and edges. Its manual says that a factor of 2 gives the best results, so start there when you want a larger-looking bitmap without changing its monochrome PBM format.

The output is written to standard output. Shell redirection creates or truncates the destination before the program finishes, so do not redirect over the only copy of a useful image. If you accidentally create a bad new file, remove that new file after checking the path; the input is unchanged.

3. Verify the result and its dimensions

Check the output with the file utility:

$ file /path/to/input.pbm input-2x.pbm
/path/to/input.pbm: PBM image data, 320 x 200
input-2x.pbm:       PBM image data, 640 x 400

The wording may vary slightly between versions of file. The useful checks are that the output is recognised as PBM and that each dimension is twice the input. A PBM is a one-bit image, so do not expect a greyscale or colour output merely because the edges have been smoothed.

For a small plain-text PBM, you can also inspect the header with:

$ head -n 2 input-2x.pbm
P4
640 400

Most Netpbm programs write raw PBM, whose magic number is P4. The remainder is binary data, so do not print the whole file in a terminal or edit it as text.

Checkpoint

Stop here if the dimensions are not the expected factor times the source. Check that the input is the file you intended and that the factor was the first argument.

4. Read from standard input when that fits the workflow

The filename is optional. This lets another command provide the PBM stream:

$ cat /path/to/input.pbm | pbmpscale 2 > input-2x.pbm

For a direct file, naming the input is easier to review. Use a pipe when the preceding command already produces PBM and you want to avoid an intermediate file. Keep diagnostics separate from the image stream: a program that writes unexpected text to standard output can corrupt the redirected PBM.

To convert a different image format first, use a suitable Netpbm converter and verify its output before scaling. Do not assume that a file ending in .pbm is valid PBM; the format header and raster still have to be readable.

5. Build larger factors from repeated two-times steps

The manual recommends repeated enlargements by 2 when the total factor is greater than 2. For an eight-times result, use separate files:

$ pbmpscale 2 input.pbm > input-2x.pbm
$ pbmpscale 2 input-2x.pbm > input-4x.pbm
$ pbmpscale 2 input-4x.pbm > input-8x.pbm
$ file input-8x.pbm
input-8x.pbm: PBM image data, 2560 x 1600

Replace the example dimensions with the dimensions of your input. Each command reads the previous file and writes the next one, so a failed step leaves the earlier checked output available. When the target factor is not a power of two, apply as many two-times steps as possible and then use the remaining positive factor. Check the final dimensions rather than relying on filenames.

6. Handle failures without guessing

A missing argument produces a usage error. A factor below one is rejected by the installed command:

$ pbmpscale 0 input.pbm > bad-output.pbm
pbmpscale: Scale argument must be at least one.  You specified 0

Do not treat a scale factor as a way to reduce an image. This command is for enlargement; use another Netpbm scaler when you need reduction or independent width and height controls.

If the input cannot be opened, check the path and permissions without changing anything:

$ ls -l /path/to/input.pbm
$ file /path/to/input.pbm

If the command reports an invalid PBM, preserve the original and inspect it with the tool that created it. Do not run the converter as root to bypass an ordinary path or permission mistake. If the output file is incomplete, discard only that newly created output and rerun after fixing the input or destination.

Done means

  • The installed command is /usr/bin/pbmpscale from Netpbm 11.5.2.
  • The scale factor was supplied before the input filename.
  • The original PBM remains intact and the result has a separate filename.
  • file recognises the result as PBM with the expected enlarged dimensions.
  • Any larger-than-two enlargement was built from checked intermediate files where practical.