Home / Alt manpages / pbmmake(1)

  • pbmmake(1)
  • User command
  • linux

Create Verified Monochrome PBM Test Images with pbmmake

Every image pipeline needs a known-good fixture to test against, and pbmmake builds one at an exact width and height in seconds. You will pick a white, black or alternating pattern, then verify the result without ever opening 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 output.

The commands only create ordinary files in that directory. None of them need sudo, and none of them touch system configuration or an input file.

1. Check the installed command

Confirm the shell runs the binary you expect, 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 columns, height is rows, and 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

White is the default colour. Redirect standard output to a new file with a .pbm suffix:

$ pbmmake 320 200 > blank-white.pbm

pbmmake writes the image to standard output as part of the normal workflow, and it normally prints no progress message on success. The result is a PBM image with 320 columns and 200 rows, all white. Verify it 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, so look for the PBM format and the requested dimensions specifically. A zero-length or missing file means the command or the redirection failed, not that you created an empty bitmap.

3. Choose black or alternating pixels

Reach for -black when you need a solid black mask or a predictable negative test:

$ 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. Grey does not mean a third pixel value here: PBM is a one-bit format, so the generated image simply 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 can be specified at once. Leave the option out for white, or spell the chosen one in full in scripts so the intended pattern is obvious on review later. The manual permits abbreviating to the shortest unique prefix, but a full option name is easier to maintain if more options turn up in a future release.

4. Inspect the PBM header when a tool is unavailable

A raw PBM starts with the magic number P4, followed by width and height. You can inspect just that 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 just formatting, 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, and for widths that are not a multiple of eight, each row includes padding bits, which is normal PBM storage rather than extra visible columns.

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, and never edit binary PBM data in a text editor.

5. Avoid overwriting a useful image

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

$ pbmmake 320 200 > blank-white.pbm

That overwrite is only reversible if you kept 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

That final mv replaces the old file when both names sit on the same filesystem. Check the temporary file is the one you actually want to keep before running it. If generation or verification fails, leave the original alone and remove only the incomplete .new file after checking its path; never 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

Warning

A positive width and height are required. If the error names 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 mere existence of a path. Shell redirection can create an empty destination before a command even reports its error, so check the exit status and then inspect the image dimensions.

Done means

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