Create Repeatable Ragged PPM Borders with ppmrough
You need a torn-paper or weathered-label placeholder for a mockup, and ppmrough builds one on the spot. It produces a PPM image with a foreground rectangle, a different-coloured background, and randomly varying edges. Better still, the raggedness is repeatable, so you can regenerate the exact same asset while you tune the dimensions. Allow about ten minutes if Netpbm is already installed.
The route
Jump straight to the step you need, or tick off Done means at the end.
Before you start
You need a Linux shell, the netpbm package, and a directory you can write a new image into. ppmrough writes binary PPM data to standard output, so redirect it to a file; do not paste it into a terminal or open it in a text editor.
This guide was checked against Netpbm 11.5.2, from Debian package netpbm 2:11.05.02-1.1build1. The installed program reports Netpbm Version 11.5.2, and the manual page documents every option used below. None of it needs elevated privileges.
1. Confirm ppmrough is on the box
Check the executable and its version before building anything around it:
command -v ppmrough
ppmrough --version
Expect a path such as /usr/bin/ppmrough and a line naming Netpbm Version 11.5.2. The version text can carry extra build detail, so match the version number rather than the whole line.
2. Generate a deterministic rectangle
Run this from a writable working directory. It produces 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, -fg the foreground. The four edge options are minimums, not exact widths, the boundary can push further out at different points. -var 14 is what makes that variation visible; a value of zero draws a straight line instead. -randomseed 42 seeds the pseudo-random generator, which is what makes this exact invocation repeatable on this installed program.
Checkpoint
The command finishes quietly and leaves a non-empty paper-edge.ppm. Confirm the header without opening the binary in an editor:
head -n 3 paper-edge.ppm
wc -c paper-edge.ppm
The first three lines should read:
P6
160 100
255
P6 marks a binary PPM, the next line gives width and height, and 255 is the maximum channel value. The full file will be larger than those header lines, three bytes per pixel add up fast.
3. Change the shape without losing repeatability
Keep the seed fixed and change 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 work as well as hex values like #7a2f4b. Leave out -width or -height and each defaults to 100. Leave out an edge option and that edge gets no requested border at all. Background defaults to black, foreground to white, variance to 10.
To compare raggedness directly, generate two files with identical 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 only fixes repeatability for one invocation, it does not make two different variance settings produce identical output.
4. Diagnose a run that looks off
Add -verbose to see exactly what ppmrough parsed. Diagnostics go to standard error while the PPM still lands on 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
The log here reports width, height, variance, the required left border, colours and seed. If a command reports an invalid colour or number, fix the option; do not save the error output as if it were an image. A negative -var value is invalid, variance has to be a nonnegative integer.
Remember ppmrough writes to standard output: a terminal full of garbage characters usually just means you forgot the redirect. If a run fails partway through, discard that incomplete file and rerun once the error is fixed. Do not overwrite a known-good image until the replacement has passed the header check.
5. Inspect or convert the result
PPM is a simple interchange format, but it is often large. Use a proper viewer or converter once the header checks out. If Netpbm's pnmtopng is installed, for instance:
pnmtopng paper-edge.ppm > paper-edge.png
That conversion reads the PPM and writes PNG to standard output; it does not touch the PPM. If you are about to replace an existing PNG, write to a new name first and inspect it before moving it into place. There is no reason to reach for sudo just because the file is an image, use it only when the destination is deliberately protected and your policy allows it.
Done means
- Version confirmed: ppmrough is installed and you know its Netpbm version.
- Header checked: the generated file begins with
P6, the expected dimensions, and255. - Parameters recorded: the edge minimums, colours, variance and seed match the image you intended.
- Repeatable: a fixed
-randomseedreproduces the same result on this installation. - Source kept: the original PPM stays available until any later conversion has been checked.