Home / Alt manpages / pnmtoddif(1)

  • pnmtoddif(1)
  • User command
  • linux

Convert PNM images to uncompressed DDIF with pnmtoddif

You will convert a PBM, PGM or PPM image into a DDIF file, choose its physical resolution, and verify that the output was created. The examples use Netpbm 11.5.2 from the installed netpbm package. Allow about ten minutes if your input image is ready.

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 is dated 2003, so the details here describe the installed command and its documented interface, rather than claiming 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. Do not copy a converter from an untrusted directory into a system path.

2. Choose the PNM input type

pnmtoddif accepts a PNM image. The format controls 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 and its data planes are interleaved by pixel. This can make the resulting file substantially larger than a compressed image format. Keep the original PNM until you have checked the DDIF file.

For a quick, harmless inspection, use file on an existing source:

$ file /path/to/source.pgm
/path/to/source.pgm: Netpbm image data, size = 4 x 2, greymap, ASCII text

Your description and dimensions will differ. The useful point is to establish that the path names the image you 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 command normally produces no progress report. The file check confirms that the destination is recognised as DDIF. It does not prove that the image looks right, so open it with a DDIF-capable application or pass it to the next tool in your workflow.

Shell redirection and positional filenames are easy to mix up. The first filename is the PNM input; the second is the DDIF output. The program does not edit 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 are the output image's horizontal and vertical resolution. They do not resize the pixel matrix or change the number of samples. The documented default is 78 dpi in both dimensions. That default was chosen for compatibility with many Digital Equipment Corporation colour monitors, but it may not match a modern display, print target or document layout.

Checkpoint: record the resolution alongside the output if the DDIF file will be exchanged or archived. A later viewer can use the metadata to calculate physical size, while the pixel width and height remain those of the source.

5. Use standard input and standard output

Both filenames are optional. With no input filename, pnmtoddif reads PNM data from standard input. With no output filename, it writes DDIF to standard output. This 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 it makes the input and output roles visible. Use standard output when another tool consumes the DDIF stream or when shell redirection is part of a controlled script.

Do not send binary DDIF to a terminal. If you need to test the stream, redirect it to a new file and inspect that file. Avoid piping it into a command that expects text.

6. Avoid destroying an existing output

Opening a destination with shell > truncates it before pnmtoddif runs. That is an irreversible loss if the old DDIF is 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 that the new file is valid before running it. If conversion fails, leave the old DDIF in place and remove only the incomplete .new file after checking its path. If the output is valuable, make a separate backup before replacing it. Do not use sudo to bypass a permissions error without first confirming that the directory and target are 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. A later command replaces that status. For a file conversion, also check that the destination is non-empty and that file recognises it as ddis/ddif.

If a consumer rejects the result, confirm that it supports the uncompressed DDIF representation and the sample depth implied by the source format. Changing -resolution changes physical-size metadata, not compression or colour depth. Re-run from the unchanged PNM with a new destination while investigating.

Done means

  • pnmtoddif is the expected Netpbm binary and its package version is known.
  • The source is a readable PBM, PGM or PPM image, and the original remains untouched.
  • The output is a non-empty DDIF file recognised by file.
  • A non-default horizontal and vertical resolution was supplied explicitly when required.
  • Any existing output was protected until the replacement had been verified.