Convert a MacPaint File to PBM with macptopbm

macptopbm turns a MacPaint file into a PBM image, and knows the fix for pictures that arrive shifted sideways from the Mac world. You will convert the file while keeping the original untouched and checking the common FinderInfo offset problem. Allow about ten minutes if the file is already on this Linux system. The command is part of Netpbm 11.5.2 here, from Debian package version 2:11.05.02-1.1build1.

You need a shell, the netpbm package and a readable MacPaint file. This guide only reads the source and writes the requested PBM output. It does not need elevated privileges unless your input or destination directory is deliberately restricted.

1. Check the installed command

Confirm which executable your shell will run, then ask it for its built-in help:

$ command -v macptopbm
/usr/bin/macptopbm
$ macptopbm --help
macptopbm: Use 'man macptopbm' for help.

The help message is brief. The installed manual documents one optional input file, -extraskip followed by a number, and common Netpbm options such as -quiet. Option names may be abbreviated to their shortest unique prefix, but full names are clearer in scripts.

Checkpoint: If command -v prints nothing, stop here and install Netpbm through your normal package-management process. Do not copy a converter from an untrusted location merely to complete this step.

2. Convert to a new PBM file

Put your actual source path in place of the example, and choose an output name that does not already contain useful data:

$ macptopbm /path/to/painting.mac > /path/to/painting.pbm

macptopbm reads the named MacPaint file and writes the PBM image to standard output. The > belongs to the shell, not to the converter. A successful run normally leaves the terminal quiet because the image bytes went to the output file.

Warning: Redirection truncates an existing destination before macptopbm starts. If painting.pbm matters, do not use that command against it until you have chosen a temporary destination or made a backup.

Verify that the result exists and that the first two bytes identify a portable bitmap:

$ test -s /path/to/painting.pbm && echo 'PBM output is non-empty'
PBM output is non-empty
$ head -c 2 /path/to/painting.pbm
P4

P4 is the binary PBM magic number. A different header or an empty file is a reason to stop and investigate. Do not open the binary image in a text editor.

3. Use a safer replacement workflow

When replacing an existing output, write beside it first, check the command status, then move the completed file into place:

$ temp_pbm=$(mktemp /path/to/painting.pbm.new.XXXXXX)
$ if macptopbm /path/to/painting.mac > "$temp_pbm"; then
>     test -s "$temp_pbm" || { echo 'empty PBM output' >&2; rm -f "$temp_pbm"; exit 1; }
>     mv -- "$temp_pbm" /path/to/painting.pbm
> else
>     status=$?
>     rm -f -- "$temp_pbm"
>     exit "$status"
> fi

This workflow changes the destination only after conversion succeeds and produces a non-empty file. The rm -f commands remove only the named temporary file. If the conversion fails, the old destination remains in place. The replacement itself is a state-changing operation, so confirm the two paths before pressing Enter.

Recovery: If you moved a bad result into place, stop using it and restore your own backup, if you made one. The converter does not keep a copy of an overwritten destination.

4. Fix a shifted image caused by FinderInfo data

Some transfers from the Mac world leave FinderInfo data at the front of the Unix file. The manual describes the visible symptom as a PBM image shifted to one side. In that case, retry with an extra 128 bytes skipped:

$ macptopbm -extraskip 128 /path/to/painting.mac > /path/to/painting-skip-128.pbm
$ test -s /path/to/painting-skip-128.pbm && echo 'candidate output created'
candidate output created

-extraskip changes where the reader starts in the input. It does not repair or rewrite the MacPaint file. If 128 does not align the image, the manual says to try another value. Keep each attempt under a distinct output name until you have inspected the result.

Do not add the option just because the file came from a Mac. Use it when the image is visibly shifted or you have evidence that the transfer prepended FinderInfo data. A clean conversion should be left alone.

5. Diagnose failures without changing the source

If the command cannot open the input, check the path and read permission:

$ ls -l -- /path/to/painting.mac
$ test -r /path/to/painting.mac && echo readable

If the converter reports an end-of-file or header error, treat the file as unreadable or not a valid MacPaint input until you have checked how it was transferred. The installed command exits non-zero for the invalid test input on this machine and writes no PBM data. Do not delete the source while troubleshooting.

If the output is shifted, retry with -extraskip 128, then compare the candidate with the original result. If the output file was accidentally truncated by a failed direct redirection, recover it from your backup or another copy. There is no undo option in macptopbm.

To read from standard input, omit the positional file argument and pipe a source into the command:

$ cat /path/to/painting.mac | macptopbm > /path/to/painting-from-stdin.pbm

Use a named input when you need to re-run the command or inspect the source path later. The pipeline is useful when another trusted tool supplies the MacPaint bytes, but it makes it easier to lose track of which file was converted.

Done means