Home / Alt manpages / ppmbrighten(1)

  • ppmbrighten(1)
  • User command
  • linux

Replace ppmbrighten Safely with pambrighten

You will finish with a working Netpbm command for brightening an image, a way to retain the old PPM file until the result is checked, and a clear answer about when ppmbrighten and pambrighten differ. On this machine the installed package is Netpbm 11.05.02-1.1build1. Allow about fifteen minutes if the input image is already available.

The short version is that ppmbrighten is obsolete. Since Netpbm 10.86, the supported replacement is pambrighten. The older command remains useful in scripts that expect its historical behaviour, but its name can hide two compatibility details: it always writes PPM, and its normalisation path is not the same as the replacement's options.

1. Check the installed commands

Start with read-only checks. Brightening an image normally needs no elevated privilege; you only need read access to the input directory and write access to the destination directory.

$ command -v ppmbrighten pambrighten pnmnorm ppmtoppm
/usr/bin/ppmbrighten
/usr/bin/pambrighten
/usr/bin/pnmnorm
/usr/bin/ppmtoppm
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ ppmbrighten --help
pambrighten: Use 'man pambrighten' for help.

The help response is a useful clue: this installation implements ppmbrighten through the newer program. Do not treat the package version above as universal. Record the version on the host where a script will run, especially if you depend on output format.

2. Make a test copy before changing the image

Choose a separate destination while testing. Shell redirection with > truncates an existing destination before the converter has proved that it can read the input. The following commands preserve the input and write a new file:

$ INPUT=/path/to/input.ppm
$ OUTPUT=/path/to/input-bright.ppm
$ test -r "$INPUT"
$ ppmbrighten -value=50 "$INPUT" > "$OUTPUT.new"
$ test -s "$OUTPUT.new"
$ mv -- "$OUTPUT.new" "$OUTPUT"
$ file "$OUTPUT"
/path/to/input-bright.ppm: Netpbm image data, ... pixmap

The -value=50 option asks for a 50 per cent increase in HSV Value. It is not a fixed number of RGB levels. A pixel already at maximum Value is clipped to full Value, so the brightest areas cannot become brighter than the format permits. Keep the original until you have inspected the new image.

If conversion fails, do not run the mv command. Remove the incomplete temporary file only after checking its name:

$ ls -l -- "$OUTPUT.new"
$ rm -- "$OUTPUT.new"
$ test -f "$OUTPUT" && echo 'previous output remains'

That final removal is destructive. It is safe here only because the old output has a different name and the input is untouched.

3. Adjust brightness and saturation deliberately

pambrighten works in HSV colour space. Value controls brightness; Saturation controls how far a colour is from grey. Each option takes a percentage, and the percentage can be positive or negative. The defaults for both are zero.

$ pambrighten -value=100 "$INPUT" > "$OUTPUT.new"
$ pambrighten -saturation=+100 -value=-50 "$INPUT" > "$OUTPUT.new"
$ pambrighten -saturation=-25 "$INPUT" > "$OUTPUT.new"

Use one command at a time while deciding what you want. The first example doubles Value. The second doubles Saturation while halving Value. The third reduces Saturation, which generally makes colours less vivid. If an increase would exceed the full HSV range, Netpbm caps that component rather than producing a value outside the image format.

The same options work with the compatibility name:

$ ppmbrighten -value=100 "$INPUT" > "$OUTPUT.new"
$ head -c 2 "$OUTPUT.new"
P6

The output begins with P6 on this installation because ppmbrighten always produces PPM, including when the input was another Netpbm format. Do not read the binary pixel data in a terminal. Use file or an image viewer after the command exits successfully.

4. Prefer pambrighten for new scripts

For new work, call pambrighten directly. It accepts the range of Netpbm image formats supported by the installed release and normally preserves the input format. Extra channels, such as a transparency channel in a PAM image, are passed through. This makes it the better default when a pipeline should not silently convert every image to PPM.

$ pambrighten -value=50 "$INPUT" > "$OUTPUT.new"
$ file "$OUTPUT.new"
/path/to/input-bright.new: Netpbm image data, ...

The exact wording from file depends on the input and the installed file utility. Check the format and dimensions rather than matching the whole sentence in a script. If a downstream program specifically requires PPM, convert the replacement's output as a separate, visible step:

$ pambrighten -value=50 "$INPUT" | ppmtoppm > "$OUTPUT.new"
$ head -c 2 "$OUTPUT.new"
P6

This explicit conversion is the practical difference between the two command names. With pambrighten, the brightening step preserves the input kind; ppmtoppm then makes the PPM requirement clear to the reader of the pipeline.

5. Handle normalisation as a separate decision

The old command has a -normalize compatibility feature. The current pambrighten interface does not provide that option. If you need to remap the input's Value range before brightening, run pnmnorm first and pass its output to pambrighten:

$ pnmnorm "$INPUT" | pambrighten -value=25 > "$OUTPUT.new"
$ test -s "$OUTPUT.new"
$ mv -- "$OUTPUT.new" "$OUTPUT"
$ file "$OUTPUT"
/path/to/input-bright.ppm: Netpbm image data, ... pixmap

Normalisation changes the tonal range before the brightness adjustment. It can make an image look harsher by stretching its darkest and lightest values, so inspect the result rather than adding it automatically to every pipeline. If you need PPM output from a non-PPM input, make the output contract explicit:

$ pnmnorm "$INPUT" | pambrighten -value=25 | ppmtoppm > "$OUTPUT.new"
$ head -c 2 "$OUTPUT.new"
P6

6. Diagnose the usual failures

A non-zero exit status means the pipeline did not complete successfully. Check the input path, permissions and temporary destination before changing options:

$ test -r "$INPUT" || echo 'input is missing or unreadable'
$ ls -l -- "$INPUT"
$ printf 'status: %s\n' "$?"

The status printed above belongs to ls, so capture a converter's status immediately when scripting. With a pipeline, the shell may report only the last command unless you enable the shell's pipeline failure handling:

set -o pipefail
if pnmnorm -- "$INPUT" | pambrighten -value=25 > "$OUTPUT.new"; then
    mv -- "$OUTPUT.new" "$OUTPUT"
else
    status=$?
    printf 'image pipeline failed with status %s\n' "$status" >&2
    rm -- "$OUTPUT.new"
    exit "$status"
fi

Do not add sudo to an ordinary conversion. Elevated privileges do not repair a malformed image or a wrong option, and they can leave root-owned output behind. Use them only when the file permissions genuinely require it, after checking that the destination will remain manageable by the account that normally processes the images.

Done means

  • You confirmed the installed Netpbm version and the four commands used by the workflow.
  • You understand that ppmbrighten is obsolete and always writes PPM.
  • New scripts use pambrighten when preserving the input format matters.
  • Brightness and saturation changes use explicit percentages and a separate output file.
  • Normalisation, when required, runs through pnmnorm before brightening.
  • The original image remains available until the converted result has been checked.