Convert PNM Images to Uncompressed DDIF with pnmtoddif
pnmtoddif turns a PBM, PGM or PPM image into a DDIF file, the format old Digital Equipment Corporation workstations expected. Allow about ten minutes if your input image is ready, including choosing a resolution and verifying the output.
The route
Jump straight to the step you need, or tick off Done means at the end.
This guide only reads the source image and creates a new output file. It does not need elevated privileges unless your chosen input or destination directory is deliberately restricted.
1. Check the installed command
Confirm the executable and package version before relying on a script or a conversion batch:
$ command -v pnmtoddif
/usr/bin/pnmtoddif
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
The local binary reports Netpbm 11.5.2. The manual page itself is dated 2003, so what follows describes the installed command and its documented interface, not a guarantee that every Netpbm release behaves identically.
Checkpoint
If command -v prints nothing, stop and install or enable the package through your normal system-management process. Never copy a converter from an untrusted directory into a system path.
2. Choose the PNM input type
pnmtoddif accepts a PNM image, and the format decides the DDIF sample layout:
- PBM bitmap data becomes a 1-bit DDIF image.
- PGM greyscale data becomes an 8-bit greyscale DDIF image.
- PPM colour data becomes an 8,8,8-bit colour DDIF image.
The output is uncompressed with its data planes interleaved by pixel, which can make the file substantially larger than a compressed format. Keep the original PNM until you have checked the DDIF file.
For a quick, harmless look at the source, use file:
$ file /path/to/source.pgm
/path/to/source.pgm: Netpbm image data, size = 4 x 2, greymap, ASCII text
Your own description and dimensions will differ; the point is confirming the path names the image you actually intend to convert.
3. Convert to a named DDIF file
Pass the PNM path first and the DDIF destination second:
$ pnmtoddif /path/to/source.pgm /path/to/source.ddif
$ file /path/to/source.ddif
/path/to/source.ddif: ddis/ddif
A successful run normally produces no progress report at all. The file check confirms the destination is recognised as DDIF; it does not prove the image looks right, so open it with a DDIF-capable application or hand it to the next tool in your workflow. Shell redirection and positional filenames are easy to mix up: the first is the PNM input, the second is the DDIF output, and the program never edits the input image.
4. Set the physical resolution
PNM records pixel dimensions but not the physical size those pixels should occupy; DDIF carries that extra information. Use -resolution followed by horizontal and vertical dots per inch when the default is not suitable:
$ pnmtoddif -resolution 96 72 /path/to/source.pgm /path/to/source-96x72.ddif
$ file /path/to/source-96x72.ddif
/path/to/source-96x72.ddif: ddis/ddif
The two numbers set the output image's horizontal and vertical resolution; they do not resize the pixel matrix or change the sample count. The documented default is 78 dpi in both directions, chosen for compatibility with many Digital Equipment Corporation colour monitors decades ago. It may not suit a modern display, print target or document layout.
Tip
Record the resolution alongside the output if the DDIF file will be exchanged or archived. A later viewer can use that metadata to calculate physical size, while the pixel width and height stay those of the source.
5. Use standard input and standard output
Both filenames are optional. Leave out the input and pnmtoddif reads PNM data from standard input; leave out the output and it writes DDIF to standard output, which makes a pipeline possible:
$ cat /path/to/source.pgm | pnmtoddif > /path/to/source.ddif
$ file /path/to/source.ddif
/path/to/source.ddif: ddis/ddif
The explicit filename form is usually easier to review because the input and output roles are visible at a glance. Use standard output when another tool consumes the DDIF stream, or when redirection is part of a controlled script. Never send binary DDIF to a terminal: if you need to test the stream, redirect it to a new file and inspect that instead.
6. Avoid destroying an existing output
Warning
Opening a destination with shell > truncates it before pnmtoddif runs, an irreversible loss if the old DDIF was the only copy. Use a temporary name, then replace the destination only after a successful conversion and verification:
$ pnmtoddif /path/to/source.pgm /path/to/source.ddif.new
$ file /path/to/source.ddif.new
/path/to/source.ddif.new: ddis/ddif
$ mv /path/to/source.ddif.new /path/to/source.ddif
mv changes the destination name, so check the new file is valid before running it. If conversion fails, leave the old DDIF in place and remove only the incomplete .new file once you have checked its path. Back up a valuable output separately before replacing it, and do not reach for sudo to bypass a permissions error without first confirming the directory and target are actually correct.
7. Diagnose the common mistakes
If the input cannot be opened, check the path and readability without changing anything:
$ ls -l /path/to/source.pgm
$ test -r /path/to/source.pgm && echo readable
readable
If the output is missing, check the command's exit status immediately after it runs, since a later command overwrites that status. For a file conversion, also confirm the destination is non-empty and that file recognises it as ddis/ddif.
If a consumer rejects the result, confirm it actually supports uncompressed DDIF and the sample depth implied by the source format. Changing -resolution only changes physical-size metadata, never compression or colour depth. Re-run from the unchanged PNM to a new destination while you investigate.
Done means
- Version known:
pnmtoddifis the expected Netpbm binary and its package version is recorded. - Source untouched: a readable PBM, PGM or PPM image, kept unchanged throughout.
- Output verified: a non-empty DDIF file recognised by
file. - Resolution set: a non-default horizontal and vertical resolution supplied explicitly when required.
- Existing output protected: nothing was replaced until the new file had been checked.