Home / Alt manpages / imagetops(1)

  • imagetops(1)
  • User command
  • linux

Convert Common Images to PostScript with imagetops

imagetops turns a PNG, JPEG, GIF, BMP or TIFF into PostScript in one command, grayscale and print size included. These examples use the imagetops supplied by Netpbm 2:11.05.02-1.1build1 on this machine.

Budget ten minutes. You need a shell, a readable image file and the netpbm package: no elevated privileges required. imagetops writes PostScript to standard output, so pick a destination on purpose rather than sending a test run straight at a printer.

1. Check the installed command

Confirm which executable runs and which package supplied it:

$ command -v imagetops
/usr/bin/imagetops
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1

The local manual calls imagetops a two-stage filter. It identifies the image format, hands it to the matching Netpbm converter to produce PNM data, then passes that to pnmtops to produce PostScript. The formats this installed manual lists are JPEG, PNG, X-PNG, BMP, X-BMP, GIF and TIFF.

Checkpoint

If command -v prints nothing, install or repair the package through your normal system administration process rather than pulling in an unrelated script to work around it.

2. Convert a file to PostScript

Point it at a real input path and redirect standard output to a new file:

$ imagetops /path/to/input.png > output.ps
pnmtops: generating color Postscript program.

That diagnostic line goes to standard error, while the PostScript document lands in output.ps. Check both the exit status and the start of the file:

$ printf 'exit status: %s\n' "$?"
exit status: 0
$ head -5 output.ps
%!PS-Adobe-3.0 EPSF-3.0
%%LanguageLevel: 2
%%Creator: pnmtops
%%Title: noname.ps
%%Pages: 1

The exact header varies with the input and the options passed to pnmtops. Status 0 means the pipeline completed; it is still worth opening the result in a PostScript-aware viewer, or a test printer, before it goes anywhere near a production job.

Watch the path. The wrapper treats a missing final file as input from standard input, so a typo can leave the command looking like it is simply waiting for data.

3. Convert standard input

When the image arrives through a pipe, leave the filename out entirely:

$ cat /path/to/input.png | imagetops > output-from-stdin.ps
pnmtops: generating color Postscript program.
$ head -1 output-from-stdin.ps
%!PS-Adobe-3.0 EPSF-3.0

imagetops stores standard input in a temporary file before it can identify the format, using $TMPDIR, or /tmp when that variable is unset. Treat that directory as part of your operational environment: check available space for unusually large images, and do not drop confidential images into shared temporary storage without a policy covering it.

In a pipeline, capture the converter's own status rather than trusting the final redirection:

$ set -o pipefail
$ cat /path/to/input.png | imagetops > output-from-stdin.ps
$ printf 'pipeline status: %s\n' "$?"
pipeline status: 0

That status only means something in a shell where pipefail is supported and switched on. Check it the way your own shell documents.

4. Request grayscale output

Add -gray when the PostScript needs grayscale image data:

$ imagetops -gray /path/to/input.png > output-grey.ps
$ printf 'exit status: %s\n' "$?"
exit status: 0
$ head -3 output-grey.ps
%!PS-Adobe-3.0 EPSF-3.0
%%LanguageLevel: 1
%%Creator: pnmtops

On this build, the flag inserts a PNM colour-to-gray conversion ahead of pnmtops. Your source image is untouched. A PostScript header is a useful format check, not visual proof, so open the file in a viewer if the difference actually matters.

There is nothing to undo here unless you overwrite an existing output file. Recover from that by restoring the file from backup or regenerating it from the original image, and use a fresh destination while you are still testing.

5. Pass page and size options to pnmtops

Anything other than -gray is forwarded straight to pnmtops. For example, request a two-inch image width:

$ imagetops -imagewidth=2 /path/to/input.png > output-two-inch.ps
$ printf 'exit status: %s\n' "$?"
exit status: 0
  • Order matters. Options come first, the image filename last: the wrapper's filename parsing depends on that shape.
  • Forwarded options. -imagewidth, -imageheight, -scale, -dpi, -width, -height, -turn and -noturn all pass through to pnmtops, whose own manual covers page positioning in full.
  • Incompatible combos. The local pnmtops manual says -imagewidth and -imageheight cannot be combined with -scale or -equalpixels. Its default page is 8.5 by 11 inches, scaled at roughly 72 input pixels per inch when the image fits; state dimensions explicitly and test the rendered page if you need exact layout.

Quote any path containing whitespace:

$ imagetops -imagewidth=2 "/path/to/Project scan.png" > "Project scan.ps"

6. Diagnose failures without changing the system

A file that is not recognised as an image gets a non-zero exit and Not an image. A recognised but unsupported MIME type gets Unsupported image type. Check the file before you retry anything:

$ file --brief --mime-type /path/to/input.png
image/png
$ imagetops /path/to/input.png > output.ps
$ printf 'status: %s\n' "$?"
status: 0

If the file itself is fine but the conversion stage fails, split the pipeline: run the matching Netpbm converter on its own, then feed its output to pnmtops. For a PNG that looks like this:

$ pngtopnm /path/to/input.png > /tmp/input.pnm
$ pnmtops /tmp/input.pnm > /tmp/input.ps
$ head -1 /tmp/input.ps
%!PS-Adobe-3.0 EPSF-3.0

Those files under /tmp are throwaway diagnostics. Clear them out with your normal temporary-file housekeeping, and skip this debugging route for sensitive images on a host where temporary storage is not properly protected.

Done means

  • Version confirmed: you checked the installed Netpbm version and executable.
  • Conversion verified: a supported image produced a PostScript file with exit status 0.
  • Grey understood: you know -gray changes the conversion pipeline, not the source image.
  • Sizing applied: you can pass compatible sizing options to pnmtops with the input filename last.
  • Errors split: you checked the MIME type and separated format errors from downstream conversion errors.
  • Output tested: you checked the result before sending it to a printer or replacing a trusted document.