Turn a PGM into a Vertical Brightness Smear with pgmbentley
pgmbentley reads a PGM and writes a second PGM carrying Netpbm's Bentley Effect: a vertical smear built from the source image's own brightness. Send the result to a different file and the original never gets touched.
The route
Jump straight to the step you need, or tick off Done means at the end.
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 the executable is on your path and note the package and library versions. All three checks below are read-only:
$ 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
Exact build details will differ on another machine. What matters is that command -v finds the binary you expect and the version output names the Netpbm library behind it.
Checkpoint
Stop here if command -v pgmbentley prints nothing. Install Netpbm through your normal package manager and repeat this step. Do not work around a missing command by downloading an untrusted binary.
2. Inspect the input before touching it
Use file or pnmfile to check the image before you process it:
$ 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 point is that the input is PGM, not a colour PPM or a renamed file wearing the wrong extension. pgmbentley accepts one optional input filename, and with none it reads standard input.
Leave the source file exactly where it is until you have checked the result. There is no in-place editing mode here, and no reason to give the program write access to your original.
3. Apply the Bentley Effect to a new file
Pass the source path and redirect standard output to a fresh 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 build it comes out as raw PGM, magic number P5, even if the input was ASCII PGM with magic number P2. That format switch is normal; the dimensions and maximum grey value carry through into the new header.
Checkpoint
Trust the file, not the 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 clean exit status only means the command finished. It says nothing about whether the effect looks good, so open the output in an image viewer or convert a copy to a format your viewer handles. Never poke a binary PGM open in a text editor.
4. Use standard input in a pipeline
If another program already produces PGM on standard output, drop the input filename and let pgmbentley sit as the final stage:
$ some-pgm-producing-command < input.dat | pgmbentley > bentley.pgm
$ pnmfile bentley.pgm
bentley.pgm: PGM raw, 1920 by 1080 maxval 255
Swap in a real, already-tested converter for some-pgm-producing-command. A pipe will not surface an upstream failure for you: depending on your shell, pgmbentley can happily process incomplete input and the final command's own success can hide the earlier one's crash. Turn on pipeline failure reporting before running anything you depend on:
$ set -o pipefail
$ some-pgm-producing-command < input.dat | pgmbentley > bentley.pgm
$ printf 'pipeline status: %s\n' "$?"
pipeline status: 0
No pipefail in your shell? Check the producer and the converter separately instead. A pipeline that leaves a half-written destination is not a valid result.
5. Avoid accidental truncation
> truncates an existing destination the instant the shell opens it, before pgmbentley has even started. That is destructive if the old file was actually useful. Pick a new name, or route through a temporary file and swap it in only after checking it:
$ tmp=$(mktemp --tmpdir pgmbentley.XXXXXX.pgm)
$ pgmbentley /path/to/source.pgm > "$tmp"
$ pnmfile "$tmp"
$ mv -- "$tmp" /path/to/checked-output.pgm
That mv is the point of no return for whatever was already at the destination. Compare dimensions and look at the image before you run it. If conversion fails, remove the temporary file with rm -- "$tmp" and the old destination is never touched. If the final file turns out wrong after the move, pull it back from your normal backup rather than deleting the source PGM.
6. Diagnose the common failures
A missing or unreadable input gives a non-zero status and an error naming the path. Check it without changing any permissions:
$ test -r /path/to/source.pgm && echo readable || echo 'cannot read input'
$ ls -l /path/to/source.pgm
An input that is not valid PGM can fail while it is being parsed. Check the file type and, if needed, regenerate the source from whatever produced it. Do not rename a PPM or a PNG to .pgm; the extension is not the format.
There are no pgmbentley-specific options in the manual, only the common libnetpbm ones. The real interface is one optional input file and standard output, so do not invent a resize, output-format or strength flag. Resize or convert the checked result with a separate Netpbm command, and verify that command on its own.
If the output is empty or pnmfile cannot read it, keep the source, discard the failed output, and rerun into a fresh destination. Do not overwrite the source while you troubleshoot, and do not reach for sudo: it will not repair malformed image data.
Done means
- Command confirmed.
pgmbentleyis the binary you expect and its version is known. - Source untouched. The input is a readable PGM and remains exactly as it was.
- Clean run. The command exited 0 and wrote a non-empty PGM to a separate path.
- Output checked.
pnmfileor an equivalent confirms the dimensions and format. - Result inspected. You looked at the image before replacing anything with it.
- Recovery in place. Any pipeline or replacement failure leaves the original recoverable and the temporary output disposable.