Home / Alt manpages / ppmspread(1)

  • ppmspread(1)
  • User command
  • linux

Soften a PPM image with repeatable pixel spreading

You will finish with a PPM image whose pixels have been moved by small random amounts, giving it a dissolved or unfocussed appearance. The examples use ppmspread from Netpbm 11.05.02, the version installed on this machine. Allow about ten minutes if your source is already a PPM file, or longer if you first need to convert another image format.

You need a shell, a readable PPM input, and enough free space for a second image. The command reads the input and writes a new PPM to standard output. It does not edit the source file, and it normally needs no elevated privileges.

1. Check the input before transforming it

Choose an input file and inspect its type and dimensions:

$ file source.ppm
source.ppm: Netpbm image data, size = 1920 x 1080, rawbits, pixmap
$ test -r source.ppm && echo readable
readable

The exact wording from file can vary. The useful checks are that the file is a PPM and that its dimensions are the ones you expect. PPM files can be ASCII or raw binary, and ppmspread accepts the PPM image rather than a filename extension, so do not assume that renaming another format is sufficient.

Checkpoint: keep source.ppm untouched. If you need to create a PPM from a PNG, JPEG or another format, use a separate converter first and verify that converter's output before running this guide.

2. Spread pixels by a small amount

Pass the maximum movement as the first argument and redirect the result to a new filename:

$ ppmspread 3 source.ppm > spread-3.ppm
$ file spread-3.ppm
spread-3.ppm: Netpbm image data, size = 1920 x 1080, rawbits, pixmap

The 3 means that each pixel may be moved around by at most three pixels from its original position. It is a maximum displacement, not a percentage, blur radius or output size. Increase it for a stronger dissolved effect, then compare the result with the source in an image viewer. Small values are usually easier to assess because the image remains recognisable.

ppmspread writes image data to standard output, so the shell redirection is part of the example. Without > spread-3.ppm, the binary result will be sent to your terminal. If you want to use a pipeline, that output can instead be consumed by another Netpbm program.

3. Protect an existing destination

Do not redirect straight over a useful file while experimenting. Shell redirection truncates its destination before ppmspread has finished. Use a new name, or make a backup before replacing anything:

$ cp --preserve=all spread-3.ppm spread-3.ppm.bak
$ ppmspread 5 source.ppm > spread-3.ppm.new
$ file spread-3.ppm.new
spread-3.ppm.new: Netpbm image data, size = 1920 x 1080, rawbits, pixmap
$ mv spread-3.ppm.new spread-3.ppm

The mv is the state-changing step. It replaces the old destination only after the new command has completed and the output has been checked. If the transformation fails, inspect or remove the incomplete spread-3.ppm.new; the original destination and its backup remain available. Once you have accepted the result, remove the backup only as a deliberate, separate cleanup action.

Warning: do not use sudo merely because an image tool is involved. Run the command as your normal user when the input and output directories are yours. Use elevated access only if your system permissions genuinely require it, and prefer copying the image into a writable working directory instead.

4. Make a result reproducible

By default, the pixel movement is random. Supply -randomseed= followed by an integer when a later run must produce the same output:

$ ppmspread 3 source.ppm -randomseed=42 > spread-seed-42-a.ppm
$ ppmspread 3 source.ppm -randomseed=42 > spread-seed-42-b.ppm
$ cmp -s spread-seed-42-a.ppm spread-seed-42-b.ppm && echo identical
identical

The option seeds the random number generator used for the pixels. Keep the amount, input bytes, Netpbm version and seed unchanged when you need a repeatable file. A different seed is expected to produce a different arrangement. The option was added in Netpbm 10.94, so it is present in the installed 11.05.02 build but may not be available in much older installations.

For a one-off visual effect, omit the option. For a build, test fixture or documented asset, record the seed beside the command. The seed controls repeatability; it does not make the image transformation cryptographically random or protect image data.

5. Diagnose a disappointing result

If the command cannot open the input, check the path and permission without changing the image:

$ ls -l source.ppm
$ test -r source.ppm && echo readable
readable

If the output is not what you expected, first confirm that the file you opened is the new output rather than the original. Then compare dimensions with file. ppmspread changes pixel positions; it does not resize the image or convert PPM to PNG, JPEG or another format. Convert the verified PPM with a separate tool if you need a compressed delivery format.

A successful exit status tells you that the command completed, not that the visual strength is suitable. Inspect the output and keep the source until you are satisfied. If a viewer rejects the result, check that the redirection was complete and that the output begins with a valid PPM header, then rerun to a fresh filename rather than overwriting the last good result.

Done means

  • The source PPM was readable and remained unchanged.
  • The first argument supplied the intended maximum pixel displacement.
  • The output was redirected to a new file and checked before any replacement.
  • -randomseed=42, or another recorded integer, was used when repeatability mattered.
  • The final PPM has the expected dimensions and has been visually inspected.