Home / Alt manpages / ppmrough(1)

  • ppmrough(1)
  • User command
  • linux

Create Repeatable Ragged PPM Borders with ppmrough

You will generate a PPM image containing a foreground rectangle, a different-coloured background, and randomly varying edges. The examples also make the random result repeatable, so you can regenerate the same asset while tuning the dimensions. Allow about ten minutes if Netpbm is already installed.

Before you start

You need a Linux shell, the netpbm package, and a directory where you can create a new image. The command writes binary PPM data to standard output. Redirect that output to a file; do not paste it into a terminal or use a text editor to inspect it.

This guide was checked with Netpbm 11.5.2, from Debian package netpbm 2:11.05.02-1.1build1. The installed program reports Netpbm Version 11.5.2. The manual page documents the options used here. No command below needs elevated privileges when you own the destination directory.

1. Check that ppmrough is available

Confirm the executable and its version before building a command around it:

command -v ppmrough
ppmrough --version

Expected output includes a path such as /usr/bin/ppmrough and a line naming Netpbm Version 11.5.2. The version text can include build details, so check the version number rather than matching the complete output.

2. Generate a deterministic rectangle

Run this in a writable working directory. It creates a 160 by 100 pixel PPM, with a minimum border on every edge:

ppmrough \
  -width 160 -height 100 \
  -left 12 -right 12 -top 8 -bottom 8 \
  -bg '#dfe8f2' -fg '#24527a' \
  -var 14 -randomseed 42 > paper-edge.ppm

-bg sets the border colour and -fg sets the foreground. The four edge options are minimum widths, not exact widths: the boundary can extend further at different points. -var 14 makes that variation visible. A value of zero produces a straight boundary. -randomseed 42 initialises the pseudo-random generator, making this invocation repeatable on the installed program.

Checkpoint

The command should finish quietly and leave a non-empty paper-edge.ppm. Verify the PPM header without opening the binary in an editor:

head -n 3 paper-edge.ppm
wc -c paper-edge.ppm

The first three lines should be:

P6
160 100
255

P6 identifies a binary PPM, the next line gives width and height, and 255 is the maximum channel value. The file size will be larger than those lines because it contains three bytes per pixel plus the header.

3. Change the shape without losing repeatability

Keep the seed while changing one parameter at a time. For a tall label-like image, try:

ppmrough \
  -width 240 -height 320 \
  -left 18 -right 18 -top 20 -bottom 20 \
  -bg white -fg '#7a2f4b' \
  -var 9 -randomseed 42 > label.ppm

Named colours such as white are accepted colour specifications, as are hexadecimal specifications such as #7a2f4b. If you omit -width or -height, each defaults to 100. If you omit the edge options, that edge has no requested border. Background defaults to black, foreground defaults to white, and variance defaults to 10.

To compare raggedness, generate two files with the same geometry and seed, changing only -var:

ppmrough -width 160 -height 100 -left 12 -right 12 -top 8 -bottom 8 -var 0 -randomseed 42 > straight.ppm
ppmrough -width 160 -height 100 -left 12 -right 12 -top 8 -bottom 8 -var 14 -randomseed 42 > ragged.ppm
cmp straight.ppm ragged.ppm && echo 'unexpectedly identical' || echo 'different pixel data'

The second command should print different pixel data. A seed controls repeatability for a given invocation; it does not make different variance settings identical.

4. Diagnose a failed or surprising run

Use -verbose when checking the parameters that ppmrough parsed. Diagnostic text goes to standard error, while the PPM still goes to standard output:

ppmrough -width 20 -height 12 -left 3 -bg red -fg white \
  -var 0 -randomseed 7 -verbose > check.ppm 2> check.log
cat check.log

For this example, the log reports the width, height, variance, required left border, colours, and seed. If a command reports an invalid colour or number, correct the option rather than saving its error output as an image. A negative value for -var is invalid because variance must be a nonnegative integer.

Remember that ppmrough writes to standard output. A terminal full of unreadable characters usually means the redirection was omitted. If an output file is incomplete because the command failed, discard that new file and rerun the command after fixing the error. Do not overwrite a known-good image until the replacement has passed the header check.

5. Inspect or convert the result

PPM is an uncomplicated interchange format, but it is often large. Use a separate viewer or converter after checking the header. For example, if Netpbm's pnmtopng is installed:

pnmtopng paper-edge.ppm > paper-edge.png

This conversion reads the PPM and writes PNG to standard output. It does not alter the PPM. If you need to replace an existing PNG, write to a new name first and inspect it before moving it into place. Do not use sudo merely because the file is an image; use elevated access only when the destination is deliberately protected and your system policy allows it.

Done means

  • ppmrough is installed and its Netpbm version is known.
  • The generated file begins with P6, the expected dimensions, and 255.
  • The edge minimums, colours, variance, and seed match the intended image.
  • A fixed -randomseed lets you reproduce the same result on this installation.
  • The original PPM remains available until any later conversion has been checked.