Home / Alt manpages / pgmbentley(1)

  • pgmbentley(1)
  • User command
  • linux

Turn a PGM into a Vertical Brightness Smear with pgmbentley

You will finish with a second PGM containing Netpbm's Bentley Effect: a vertical smear based on the source image's brightness. The command reads a PGM and writes a PGM, so the original stays untouched if you write the result to a different file.

Allow about ten minutes. You need Netpbm's pgmbentley, a readable PGM image, and a writable working directory. The examples use Netpbm 11.5.2, installed here as Debian package netpbm 2:11.05.02-1.1build1. This is an ordinary image conversion and does not need sudo.

1. Check the installed command

Confirm that the executable is on your path and record the local package and library versions. These are read-only checks:

$ command -v pgmbentley
/usr/bin/pgmbentley
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ pgmbentley -version
pgmbentley: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
pgmbentley: Built from source dated 2024-03-31 09:09:47

The exact build details can differ on another machine. The useful checks are that command -v finds the intended binary and that the version output identifies the Netpbm library in use.

Checkpoint

Stop here if command -v pgmbentley prints nothing. Install Netpbm through your normal package-management process, then repeat this step. Do not work around a missing command by downloading an untrusted binary.

2. Inspect the input before changing anything

Use file or pnmfile to check the image you intend to process:

$ file /path/to/source.pgm
/path/to/source.pgm: Netpbm image data, size = 1920 x 1080, greymap, rawbits
$ pnmfile /path/to/source.pgm
/path/to/source.pgm: PGM raw, 1920 by 1080  maxval 255

Your dimensions and wording may differ. The important point is that the input is PGM, not a colour PPM or an unrelated file with a renamed extension. pgmbentley accepts one optional input filename. With no filename, it reads standard input.

Keep the source file in place until you have checked the result. The program does not provide an in-place editing mode, and there is no reason to give it write access to the original.

3. Apply the Bentley Effect to a new file

Pass the source path and redirect standard output to a new destination:

$ pgmbentley /path/to/source.pgm > /path/to/source-bentley.pgm
$ printf 'exit status: %s\n' "$?"
exit status: 0

The output is a PGM image. On this Netpbm build it is written as raw PGM, whose magic number is P5, even when the input was an ASCII PGM with magic number P2. That format change is normal. The image dimensions and maximum grey value remain part of the output header.

Checkpoint

Verify the destination rather than trusting the shell prompt:

$ pnmfile /path/to/source-bentley.pgm
/path/to/source-bentley.pgm: PGM raw, 1920 by 1080  maxval 255
$ test -s /path/to/source-bentley.pgm && echo 'output is non-empty'
output is non-empty

A successful exit status means the command completed. It does not tell you whether the visual effect is useful, so open the output with an image viewer or convert a copy to a format your viewer supports. Do not edit the binary PGM in a text editor.

4. Use standard input in a pipeline

If another program produces PGM on standard output, omit the input filename. This keeps pgmbentley as the final image-processing stage:

$ some-pgm-producing-command < input.dat | pgmbentley > bentley.pgm
$ pnmfile bentley.pgm
bentley.pgm: PGM raw, 1920 by 1080  maxval 255

Replace some-pgm-producing-command with a real converter that you have already tested. The pipe does not preserve a failed upstream command automatically: depending on your shell, pgmbentley can still receive incomplete input and the final command can hide the earlier failure. For a script, enable pipeline failure reporting before the pipeline:

$ set -o pipefail
$ some-pgm-producing-command < input.dat | pgmbentley > bentley.pgm
$ printf 'pipeline status: %s\n' "$?"
pipeline status: 0

If your shell does not support pipefail, check the producer and converter separately. A pipeline that writes a partial destination is not a valid image result.

5. Avoid accidental truncation

Shell redirection with > truncates an existing destination before pgmbentley starts. That is destructive if the destination already contains a useful image. Choose a new name, or use a temporary file and replace the old destination only after verification:

$ tmp=$(mktemp --tmpdir pgmbentley.XXXXXX.pgm)
$ pgmbentley /path/to/source.pgm > "$tmp"
$ pnmfile "$tmp"
$ mv -- "$tmp" /path/to/checked-output.pgm

The mv is the point of no return for the old destination if that path already exists. Before running it, compare the dimensions and inspect the image. If conversion fails, remove the temporary file with rm -- "$tmp"; the original destination remains unchanged. If the final file is wrong after the move, restore it from your normal backup rather than deleting the source PGM.

6. Diagnose the common failures

A missing or unreadable input produces a non-zero status and an error naming the path. Check it without changing permissions:

$ test -r /path/to/source.pgm && echo readable || echo 'cannot read input'
$ ls -l /path/to/source.pgm

If the input is not valid PGM, the command can fail while parsing it. Check the file type and, if necessary, regenerate the source from the program that produced it. Do not rename a PPM or a PNG to .pgm; the extension is not the format.

The manual defines no options specific to pgmbentley. It recognises common libnetpbm options, but the practical interface is one optional input file and standard output. Do not invent resize, output-format or strength flags. Resize or convert the verified result with a separate Netpbm command, and verify that command independently.

If the output is empty or cannot be read by pnmfile, keep the original source, discard the failed output, and rerun with a fresh destination. Do not overwrite the source while troubleshooting. No elevated privileges are needed unless your file permissions genuinely require them; using sudo will not repair malformed image data.

Done means

  • pgmbentley is the expected Netpbm binary and its installed version is known.
  • The input is a readable PGM and remains untouched.
  • The command completed with status 0 and wrote a non-empty PGM to a separate path.
  • pnmfile or an equivalent check confirms the output dimensions and format.
  • You inspected the visual result before replacing any existing destination.
  • Any pipeline or replacement failure has a recoverable original and a disposable temporary output.