Home / Alt manpages / leaftoppm(1)

  • leaftoppm(1)
  • User command
  • linux

Convert Interleaf Images to PPM with leaftoppm

leaftoppm is a small, single-purpose Netpbm tool that turns an old Interleaf image file into a PPM you can actually open. This guide produces that PPM and runs a quick check that the output is a genuine Netpbm image. The examples use the installed Netpbm 11.5.2 binary on Debian, but the utility itself is an old, narrow converter.

Allow about ten minutes. You need a readable Interleaf image file and a writable working directory. No command in this guide needs sudo. The converter does not change the input file, system configuration or a running service.

1. Check the installed program

Confirm which executable is being used and record the Netpbm version reported by the binary:

$ command -v leaftoppm
/usr/bin/leaftoppm
$ leaftoppm --version
leaftoppm: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
leaftoppm: Built from source dated 2024-03-31 09:09:47

The Debian package version is also worth recording when comparing machines:

$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1

Checkpoint

The path should point to the Netpbm executable you intend to run. If command -v finds nothing, install Netpbm through your normal package-management process rather than copying a binary from an unrelated host.

2. Check the input without changing it

leaftoppm accepts one optional file name: with a file name it reads that file, with none it reads standard input. Start by confirming your source exists and is readable:

$ INPUT='/path/to/source.leaf'
$ ls -l -- "$INPUT"
-rw-r--r-- 1 alice alice 48216 Sep 24 10:15 /path/to/source.leaf
$ test -r "$INPUT" && echo 'input is readable'
input is readable

The file extension is not a format check. An ordinary PPM, PNG or empty file is no substitute for a real Interleaf image: the installed program expects the Interleaf format specifically and rejects other input before producing anything.

There is a confusing defect in the installed manual worth knowing about upfront: its NAME says the command converts Interleaf to PPM, but its DESCRIPTION says the reverse. The executable settles the argument by behaviour: it rejects a valid PPM beginning with P6 and reports a bad magic number. Trust the NAME and the actual behaviour over the stale DESCRIPTION.

3. Convert to a new output file

Send standard output to a new temporary name, then move it into place only after the command succeeds:

$ OUTPUT='/path/to/source.ppm.new'
$ leaftoppm -- "$INPUT" > "$OUTPUT"
$ status=$?
$ printf 'leaftoppm exit status: %s\n' "$status"
leaftoppm exit status: 0
$ mv -- "$OUTPUT" '/path/to/source.ppm'

The -- makes the boundary before the file name explicit. There are no leaftoppm-specific options documented, so do not invent flags for dimensions, compression or output format that do not exist. The PPM data goes to standard output; shell redirection alone decides the destination.

  • Never redirect straight to the real file. Skip > /path/to/source.ppm when that file already holds an image you might need, since redirection truncates the destination before leaftoppm even runs.
  • If conversion fails, keep the old file and remove only the incomplete temporary output:
    $ rm -- '/path/to/source.ppm.new'
    That rm is an irreversible deletion of the failed temporary file, so check the path before running it.

Following the temporary-name workflow means the original Interleaf input and any existing PPM stay untouched throughout.

4. Verify the PPM header and dimensions

Use a file-identification tool first:

$ file '/path/to/source.ppm'
/path/to/source.ppm: Netpbm image data, size 640 x 480, rawbits, pixmap

For a PPM, inspect the first three header fields as a second check. This reads the output and does not modify it:

$ head -n 3 '/path/to/source.ppm'
P6
640 480
255

P6 means a binary colour PPM. The width, height and maximum sample value shown are examples, not defaults: use whatever your own file actually prints. Do not use head -n to peek at the pixel data past the header, because binary bytes can contain newlines. Confirm the file is non-empty too:

$ test -s '/path/to/source.ppm' && echo 'PPM is non-empty'
PPM is non-empty

A successful exit status proves the converter completed, not that the image is visually correct. Open the PPM with a trusted viewer, or pass it to a separate Netpbm converter such as pnmtopng if that is installed.

5. Use standard input when a pipeline is useful

The optional file argument lets you feed an Interleaf file through standard input. Handy when another command supplies the file, but it makes diagnosis less direct, so stick to a named input while troubleshooting:

$ cat -- '/path/to/source.leaf' | leaftoppm > '/path/to/source.ppm.new'
$ test -s '/path/to/source.ppm.new' && echo 'pipeline produced output'
pipeline produced output

Do not use this form with a command that produces text, a different image format, or untrusted arbitrary bytes. A malformed stream can result in a non-zero exit and no useful PPM. Keep the temporary output until you have checked the status and header, then move it into place as in step 3.

6. Diagnose failures

A missing or unreadable input normally fails before a useful image gets written. Check the exact path and permissions:

$ ls -l -- "$INPUT"
$ test -r "$INPUT" && echo readable || echo 'not readable'
$ leaftoppm -- "$INPUT" > '/path/to/source.ppm.new'
$ printf 'exit status: %s\n' "$?"
exit status: 1
  • "Bad magic number": inspect the source type rather than trying random options. A valid PPM is deliberately not valid input for this utility, whatever the stale DESCRIPTION in the manpage claims.
  • Empty or incomplete output after a failure: discard that temporary file and keep the source for another attempt.
  • Succeeds but file does not identify a Netpbm image: stop before replacing an existing output. Check the command path, package version and source file with whoever supplied the Interleaf data. Do not run the converter as root to bypass a format or data problem.

Done means

  • Executable confirmed. leaftoppm is the intended Netpbm executable and its installed version is known.
  • Real Interleaf source. Not merely a file with a matching extension.
  • Clean conversion. The converter exits with status 0 and writes a new PPM without overwriting an existing image.
  • Output verified. file identifies the result as Netpbm data and its header reports the expected dimensions.
  • Nothing lost. The original source remains available, and a failed temporary output can be removed without touching the previous PPM.