Convert Solitaire Image Recorder Files to PNM with sirtopnm
A stray .sir file from an old scanner or fax card is useless until sirtopnm turns it into a PGM or PPM you can actually open. You will finish with a converted image plus a quick check that the format and dimensions are sensible. The examples use sirtopnm from Netpbm 11.05.02-1.1build1, installed here on Linux, and the whole thing takes about ten minutes.
The route
Jump straight to the step you need, or tick off Done means at the end.
You need a readable Solitaire file, a shell, and enough free space for the output. This is an ordinary user-level conversion: it should not need sudo. Keep the original file until you have checked the converted image.
1. Check the installed command
Confirm which executable will run and record the package version. These are read-only checks:
$ command -v sirtopnm
/usr/bin/sirtopnm
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 11.05.02-1.1build1
The installed manual describes sirtopnm as a converter for Solitaire Image Recorder files. It has no command-line options specific to this program: it just takes one optional input filename, so the interface is deliberately small.
Checkpoint
If command -v prints nothing, stop and install Netpbm through your normal package-management process. Do not copy a binary from an unknown source merely to process an old image.
2. Inspect the input before converting it
Use a path to the file you actually intend to read. Check that it exists and is readable without changing it:
$ INPUT='/path/to/image.sir'
$ ls -l -- "$INPUT"
$ test -r "$INPUT" && echo 'input is readable'
input is readable
Replace the placeholder with your real path. Quoting the variable protects spaces and most shell metacharacters in the filename. If ls reports the file does not exist, fix the path first: a permission problem is not solved by changing the file or running the converter as root.
SIR files are often identified by their contents rather than their filename suffix. If file is installed, it gives a useful, non-destructive hint:
$ file -- "$INPUT"
/path/to/image.sir: Solitaire Image Recorder format MGI Type 17
The exact wording varies with the file and the installed file database. An MGI Type 17 file is the grayscale form; an MGI Type 11 file is the 24-bit colour form.
3. Convert to a new output file
sirtopnm writes the converted PNM image to standard output. Redirect it to a new filename so a failed conversion cannot truncate an existing image:
$ OUTPUT='/path/to/image.pnm'
$ sirtopnm -- "$INPUT" > "$OUTPUT"
sirtopnm: Writing a PGM file
That diagnostic tells you the output family: MGI Type 17 writes PGM, MGI Type 11 writes PPM. It goes to standard error while the image bytes go to the redirected standard output, so do not redirect standard error into the image file.
The -- marker makes the boundary between the command and the input path explicit, and the installed program accepts it in this position. If your filename begins with a hyphen, this also stops it being read as an option, though the safer habit is still to store image files with ordinary names.
There is no overwrite protection in shell redirection. The > operator truncates an existing destination before sirtopnm even starts. Before using an important output name, choose a new path or make a copy:
$ OUTPUT='/path/to/image.pnm.new'
$ sirtopnm -- "$INPUT" > "$OUTPUT"
$ test -s "$OUTPUT" && echo 'conversion produced a non-empty file'
conversion produced a non-empty file
Only after checking the new file should you replace an older result. If the conversion fails, remove the incomplete .new file with the exact path you selected. Warning: that deletion is irreversible, so do not include it in an unattended batch until the workflow is proven.
4. Convert from standard input when needed
With no filename argument, sirtopnm reads the SIR data from standard input, which is handy in a pipeline or when another program supplies the bytes:
$ sirtopnm < '/path/to/image.sir' > '/path/to/image.pnm'
sirtopnm: Writing a PGM file
The two redirects have different jobs: the left one supplies the input stream, the right one captures the PNM output. Keep the diagnostic visible so you can tell whether the result is PGM or PPM, and avoid pipelines that hide a failed producer unless you also check the pipeline's status in your shell.
5. Verify the output before using it
Check first that the destination is non-empty and that its image type matches what sirtopnm reported:
$ file -- "$OUTPUT"
/path/to/image.pnm: Netpbm image data, size = 640 x 480, rawbits, greymap
$ head -c 2 -- "$OUTPUT"
P5
- Colour result.
filenormally reports a pixmap and the PNM magic number isP6. - Grayscale result.
filenormally reports a greymap and starts withP5. - Dimensions. These depend on the source, so do not treat the sample size above as a default.
Do not inspect a binary PGM or PPM in a text editor: its header is text but the pixel data is binary. Open it with an image viewer, or pass it to a separate Netpbm converter if you need a more convenient format; check that later conversion separately.
6. Diagnose a failed conversion
A missing or unreadable input usually points to the path or permissions. Re-run the read-only checks:
$ ls -l -- "$INPUT"
$ test -r "$INPUT" && echo readable || echo 'not readable'
not readable
If the input is readable but sirtopnm rejects it, preserve the original and capture the diagnostic in a separate text file while testing a fresh destination:
$ sirtopnm -- "$INPUT" > '/tmp/sirtopnm-test.pnm' 2> '/tmp/sirtopnm-test.err'
$ cat '/tmp/sirtopnm-test.err'
$ test -s '/tmp/sirtopnm-test.pnm' && echo 'output exists'
output exists
An output file existing does not prove the conversion is usable, so still run file and inspect the image. If the source is corrupt or not a supported SIR file, keep it unchanged and recover another copy from the original archive. Do not try to repair the source by editing binary bytes.
Done means
- Version confirmed: the installed Netpbm version and sirtopnm executable were checked.
- Input verified: the file was confirmed readable without modifying it.
- Safe write: a new output file was created with standard output redirection.
- Format matched: the diagnostic identified PGM or PPM, and
fileconfirmed the result. - Magic number checked:
P5for grayscale orP6for colour. - Original kept: the source SIR file remains available for recovery.