Home / Alt manpages / pbmmake(1)

  • pbmmake(1)
  • User command
  • linux

Create Verified Monochrome PBM Test Images with pbmmake

You will create a PBM bitmap at an exact width and height, choose a white, black or alternating black-and-white pattern, and verify the file without opening it in an image editor. This guide uses Netpbm 11.5.2 from package version 2:11.05.02-1.1build1, installed on the reference machine.

Allow about ten minutes. You need a shell, the netpbm package and a directory where you can write the output. The commands create ordinary files in that directory. They do not need sudo, and they do not alter system configuration or any input file.

1. Check the installed command

Confirm that the shell will run the expected binary and record the package version:

$ command -v pbmmake
/usr/bin/pbmmake
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1

The installed manual describes the interface as pbmmake [-white|-black|-gray] width height. The two dimensions are positional arguments, not options. Width is the number of columns and height is the number of rows. Both must be positive numbers.

Checkpoint: if command -v prints nothing, stop here and install Netpbm through your normal package-management process. Do not copy a binary into /usr/local/bin just to make this one example work.

2. Create the default white bitmap

The default colour is white. Redirect standard output to a new file with a .pbm suffix:

$ pbmmake 320 200 > blank-white.pbm

pbmmake writes the image to standard output, so the redirection is part of the normal workflow. On success it normally prints no progress message. The output is a PBM image with 320 columns and 200 rows, all white.

Verify the result with the Netpbm file inspector if it is installed:

$ pamfile blank-white.pbm
blank-white.pbm: PBM raw, 320 by 200

The wording can vary slightly between package versions. Look for the PBM format and the requested dimensions. A zero-length or missing file means the command or the redirection failed, not that an empty bitmap was created.

3. Choose black or alternating pixels

Use -black when a solid black mask or a predictable negative test is needed:

$ pbmmake -black 64 48 > mask-black.pbm
$ pamfile mask-black.pbm
mask-black.pbm: PBM raw, 64 by 48

Use -gray for the documented dithered result. In this command, grey does not mean a third pixel value: PBM is a one-bit format, so the generated image alternates black and white pixels:

$ pbmmake -gray 64 48 > checker.pbm
$ pamfile checker.pbm
checker.pbm: PBM raw, 64 by 48

Only one of -white, -black and -gray may be specified. Leave the option out for white, or spell the chosen option in full in scripts so that the intended pattern is obvious during review. The manual permits abbreviating an option to its shortest unique prefix, but a full option is easier to maintain if more options are added in a future release.

4. Inspect the PBM header when a tool is unavailable

A raw PBM normally starts with the magic number P4, followed by the width and height. You can inspect just the first part without treating the binary raster as text:

$ od -An -tc -N 32 checker.pbm
   P   4  \n   6   4       4   8  \n

The spacing in od output is formatted, so do not compare it character for character. The useful checks are the P4 marker and the two dimensions. The bytes after the header are packed pixel bits. For widths that are not a multiple of eight, each row includes padding bits; that is normal PBM storage, not extra visible columns.

If you need a text representation for a small diagnostic image, convert a copy with pnmtoplainpnm:

$ pnmtoplainpnm checker.pbm > checker-plain.pbm
$ sed -n '1,8p' checker-plain.pbm
P1
64 48

This conversion is optional and produces a larger, human-readable PBM. Keep the raw file when it is the input to another image tool. Do not edit binary PBM data in a text editor.

5. Avoid overwriting a useful image

Shell redirection opens the destination before pbmmake runs. If blank-white.pbm already exists, this command truncates it immediately:

$ pbmmake 320 200 > blank-white.pbm

That overwrite is reversible only if you have a copy. For a replacement you want to inspect first, write a temporary name and move it into place after verification:

$ pbmmake -white 320 200 > blank-white.pbm.new
$ pamfile blank-white.pbm.new
blank-white.pbm.new: PBM raw, 320 by 200
$ mv -- blank-white.pbm.new blank-white.pbm

The final mv replaces the old file when both names are on the same filesystem. Before running it, check that the temporary file is the one you intend to keep. If generation or verification fails, leave the original alone and remove the incomplete .new file only after checking its path. Do not use a broad wildcard for cleanup.

6. Diagnose a failed invocation

Test invalid dimensions in a scratch directory or capture the error without overwriting a useful destination:

$ pbmmake 0 200 > /tmp/pbmmake-invalid.pbm
pbmmake: Width argument must be a positive number.  You specified 0.
$ printf 'exit status: %s\n' "$?"
exit status: 1

A positive width and height are required. If the error mentions an invalid dimension, correct the value rather than trying sudo. Elevated privileges do not make a malformed bitmap request valid.

If the output file is missing or unexpectedly empty, check the destination directory and capture the command status:

$ pbmmake -black 64 48 > mask-black.pbm
$ status=$?
$ printf 'pbmmake status: %s\n' "$status"
pbmmake status: 0
$ test -s mask-black.pbm && printf '%s\n' 'output is non-empty'
output is non-empty

Do not infer success from the existence of a path alone. Shell redirection can create an empty destination before a command reports an error. Check the exit status and then inspect the image dimensions.

Done means

  • pbmmake is the installed Netpbm command you intended to run.
  • The output has the requested width and height, verified by pamfile or its equivalent.
  • You selected white, black or the alternating -gray pattern deliberately.
  • You understand that output goes to standard output and that shell redirection can truncate an existing file.
  • Any replacement was generated under a temporary name and moved only after verification.