Home / Alt manpages / ppmtopict(1)

  • ppmtopict(1)
  • User command
  • linux

Convert a PPM Image to Macintosh PICT with ppmtopict

Someone hands you a PPM and wants something a classic Mac program can open: ppmtopict converts it into a Macintosh PICT data fork. You will check the output is non-empty and keep the original recoverable if conversion fails. The examples use Netpbm 11.5.2, the version installed on this machine. Allow about ten minutes for a single image.

You need the netpbm package, a readable PPM input, and a directory where you can create the output. This is an ordinary user workflow: it should not need sudo, unless your input or destination permissions already require it.

1. Check the installed command

Confirm the shell runs the Netpbm program you expect and record its package version:

$ command -v ppmtopict
/usr/bin/ppmtopict
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ ppmtopict --version
ppmtopict: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
ppmtopict: Built from source dated 2024-03-31 09:09:47

That version line is diagnostic text, not a conversion option. The manual page for this installed package documents one optional operand, ppmfile, and no ppmtopict-specific options. With no file operand, the program reads the PPM image from standard input.

Checkpoint

If command -v finds nothing, stop and install Netpbm through your normal package-management process. Do not copy a random binary into a system directory.

2. Inspect the PPM before converting it

Check the input path without changing it:

$ test -r /path/to/input.ppm && echo 'input is readable'
input is readable
$ file /path/to/input.ppm
/path/to/input.ppm: Netpbm image data, size = 800 x 600, pixmap
  • The exact wording varies. It depends on the file utility and whether the PPM is plain text or binary.
  • You are only proving existence and type. Not that every pixel is correct.
  • Watch the width. The installed converter rejects an image narrower than eight pixels, and that boundary is easy to hit with a tiny test image, so use a real image or check its dimensions first.

3. Write a PICT file without destroying an existing one

Redirection sends ppmtopict's standard output to a file. Because > truncates an existing destination before the program even starts, convert to a new temporary name first:

$ ppmtopict /path/to/input.ppm > /path/to/output.pict.new
ppmtopict: computing colormap...
ppmtopict: 247 colors found
$ test -s /path/to/output.pict.new
$ mv /path/to/output.pict.new /path/to/output.pict

The colour count is informational and varies with the image. The exit status, followed by the non-empty-file check, is your real success signal. That final mv changes the destination directory, so only run it when the new file is the replacement you actually want. If conversion fails, the .new file may be incomplete: leave the old output alone and remove the failed temporary file with your normal file-management tool.

Warning

If output.pict already exists, pause before the final move. Rename the old file to a dated backup or choose another destination. Do not delete something irreversibly just to tidy up a test.

4. Confirm the output and its format boundary

PICT is not a text format, so inspect it with file-size and byte-oriented tools rather than a text editor:

$ wc -c /path/to/output.pict
652 /path/to/output.pict
$ test -s /path/to/output.pict && echo 'PICT data fork is non-empty'
PICT data fork is non-empty

Your byte count will differ. This confirms output was written, not that the image looks right. Open it with a Macintosh-compatible PICT reader, or a tool that explicitly supports PICT. Do not rename the file and assume a different extension changes its contents.

For a repeatable smoke test, the converter can read standard input. These two commands should produce byte-for-byte identical output when fed the same PPM:

$ ppmtopict /path/to/input.ppm > /tmp/from-file.pict
$ cat /path/to/input.ppm | ppmtopict > /tmp/from-stdin.pict
$ cmp /tmp/from-file.pict /tmp/from-stdin.pict
$ echo $?
0

The temporary files are ordinary data and can be removed after the comparison. Keep the source PPM until the consuming software has checked the PICT.

5. Handle the Macintosh file-format limitation

ppmtopict writes only the data fork of a picture. The manual warns this is not, by itself, a complete MacBinary or BinHex-wrapped file with the metadata classic Mac OS needs to identify a PICT file. If you need that packaging, use a suitable tool such as mcvert after checking it is installed and its conventions match your target system.

A successful ppmtopict exit status is not proof that an old Macintosh workflow will accept the result. Verify the PICT data first, then test the packaging step separately: that way a failure clearly belongs to image conversion or to file wrapping, not both at once.

6. Diagnose a failed conversion

If ppmtopict reports it cannot open the input, check the exact path and read permission:

$ ls -l /path/to/input.ppm
$ test -r /path/to/input.ppm && echo readable
  • Too narrow. Use an image at least eight pixels wide.
  • Malformed PPM data. Regenerate or repair the PPM with the tool that created it rather than guessing at binary bytes.
  • No output produced. Check the command status immediately and do not move the temporary file into place.

There is no persistent configuration to undo here. A failed conversion only affects the newly redirected file, and if you used the temporary-name pattern, the existing PICT stays available until you deliberately replace it.

Done means

  • ppmtopict is the intended Netpbm 11.5.2 installation.
  • The PPM is readable and at least eight pixels wide.
  • Conversion completed with a successful exit status and produced a non-empty PICT data fork.
  • An existing output was protected by converting to a new name first.
  • Any MacBinary or BinHex packaging is treated as a separate, verified step.