Home / Alt manpages / pamtodjvurle(1)

  • pamtodjvurle(1)
  • User command
  • linux

Convert a Netpbm Image to DjVu RLE with pamtodjvurle

pamtodjvurle exists for one reason: some other DjVu tool insists on colour RLE input and nothing else will do. It turns a PNM or PAM image into that exact format and writes the result to standard output, so the real risk is not the conversion itself, it is dumping binary data straight onto your terminal.

You need: a Linux system with the netpbm package, a readable PNM or PAM image, and a shell. No elevated privileges. Budget five minutes for a first conversion, including checking the result.

1. Check the installed command

Confirm which executable will actually run and note its Netpbm version before you do anything else. An installed program's real argument handling always beats a copied example from someone else's machine.

command -v pamtodjvurle
pamtodjvurle --version

On the system used for this guide, the executable is /usr/bin/pamtodjvurle from Debian's netpbm 2:11.05.02-1.1build1, reporting Netpbm 11.5.2. The version switch prints build information and exits; it does not convert an image.

2. Convert the image and check the output

pamtodjvurle accepts a Netpbm image: a PNM image, or a PAM image carrying the equivalent PNM image data. PAM is the general Netpbm format; its header describes width, height, depth, maximum sample value and tuple type. The converter writes DjVu colour RLE to standard output.

The manual page shows an optional output filename in its synopsis, but the installed 11.5.2 binary rejects two positional filenames. Treat the output as stdout and redirect it yourself. That also keeps the binary stream explicit and away from your terminal.

pamtodjvurle /path/to/input.ppm > /path/to/output.rle

Replace both paths with real values. The command above needs no root access. Redirection creates or replaces output.rle, so check the destination before running it: if it already holds something useful, pick a new filename or make a backup first.

A successful run is normally silent and returns exit status zero. Confirm the file exists and is not empty:

test -s /path/to/output.rle && file /path/to/output.rle

For a quick local test, build a PPM without touching anything else on the system:

printf 'P3\n2 1\n255\n255 255 255  255 0 0\n' > /tmp/example.ppm
pamtodjvurle /tmp/example.ppm > /tmp/example.rle
test -s /tmp/example.rle && file /tmp/example.rle

The generated file is binary data. Do not open it in a text editor or print it with cat. On this machine the first bytes read R6, followed by the image dimensions: a useful sanity check, but not a substitute for validating against whatever actually consumes the file.

3. Choose the transparent colour

White is transparent by default, and that is easy to miss: white pixels in the source may not stay opaque once the DjVu data is consumed elsewhere. If white is part of the visible artwork, choose a different transparent colour, or one that is not present in the image at all.

pamtodjvurle -transparent black /path/to/input.ppm > /path/to/output-black-transparent.rle

The value after -transparent is a colour name understood by Netpbm's colour parser. A simple name such as black or red is usually enough. The option changes how matching image pixels are marked in the DjVu output; it does not add an alpha channel to the source image.

Verify the conversion the same way:

test -s /path/to/output-black-transparent.rle && file /path/to/output-black-transparent.rle

Do not assume two output files will be the same size. Changing the transparent colour changes the encoded image, and file size on its own proves nothing about correctness.

Common traps

  • Two filenames: do not pass an input and output filename as separate arguments on the installed Debian build. It reports that it takes at most one argument. Use shell redirection for the output.
  • Binary output in the terminal: redirect stdout before running the converter. If you already sent bytes to a terminal, clear the display and rerun with redirection; the source image is not modified.
  • Unexpected transparency: remember that white is the default. Repeat the conversion with -transparent set to the colour that should actually be transparent.
  • Input errors: a missing path, unreadable file or malformed PNM/PAM input causes a non-zero exit. Check the path and format first; do not treat a zero-byte output as a valid DjVu file.
  • Overwriting a result: shell redirection truncates the destination before the program runs. If conversion fails, the previous destination may already be gone. Use a new output path, or write to a temporary file and rename it only after verification.

Safer replacement workflow

For an output you actually care about, convert to a temporary file in the same directory, check it, then replace the destination. The final move is an overwrite, so keep a backup if recovery would matter.

tmp=/path/to/output.rle.tmp
pamtodjvurle /path/to/input.ppm > "$tmp" && test -s "$tmp" && mv -- "$tmp" /path/to/output.rle

This is an ordinary user operation when the directory is writable. If the destination is owned by root, stop and choose a user-writable staging directory or use an approved administrative procedure. Do not reach for sudo merely because the conversion command failed.

If the conversion fails after creating the temporary file, inspect its error output and remove that temporary file deliberately, after confirming it is the one you created. The source image remains unchanged throughout.

Done means

  • Version checked: pamtodjvurle --version identified the Netpbm build you tested.
  • Valid input: the source was a readable PNM or PAM image.
  • Clean exit: the command completed with exit status zero and stdout was redirected.
  • Non-empty output: test -s confirmed a real DjVu colour RLE file.
  • Transparency chosen: you picked a transparent colour deliberately, instead of relying on white by accident.