Home / Alt manpages / pamtotiff(1)

  • pamtotiff(1)
  • User command
  • linux

Convert Netpbm Images to TIFF Safely with pamtotiff

By the end of this guide, a PNM or PAM image will be a checked TIFF file, with an intentional choice of output path, compression and colour representation. The examples use the Netpbm 11.5.2 package installed on Ubuntu and take about five minutes if your input is ready.

Before you start

You need the pamtotiff command and a PNM or PAM input such as a PBM, PGM or PPM file. No elevated privileges are needed when reading your own input and writing to a directory you control. Do not use sudo just to convert an image. This command creates or changes the named output file, so choose a new path or make a backup before using an existing TIFF.

Checkpoint

The normal workflow is input image, explicit output file, then an independent file check.

1. Check the installed command

Confirm which executable will run and record its Netpbm version. This matters when copying a command to an older host: the current output-file interface arrived in Netpbm 10.67, and older releases behaved differently.

$ command -v pamtotiff
/usr/bin/pamtotiff
$ pamtotiff --version
pamtotiff: Using libnetpbm from Netpbm Version: Netpbm 11.5.2

Your build may print extra lines after the version. If the command is missing, install the distribution's netpbm package through its normal package-management process, then repeat this check.

2. Convert one image to a new TIFF

Use -output when you want pamtotiff to write directly to a regular file. The file must be readable and seekable. This avoids the extra temporary-file copy used when the TIFF is written to standard output.

$ pamtotiff -output '/path/to/result.tif' '/path/to/source.pnm'
$ file '/path/to/result.tif'
/path/to/result.tif: TIFF image data, ...

Replace both placeholders with real paths. Quoting them protects spaces and shell metacharacters. If result.tif already contains data, the current program appends another TIFF image to it. That is a significant default: it does not replace an existing non-empty TIFF.

For a one-off pipeline, standard output is also valid:

$ pamtotiff '/path/to/source.pnm' > '/path/to/result.tif'
$ file '/path/to/result.tif'

Do not use a shell redirection into the same file as the input. The shell truncates the destination before pamtotiff can read it, destroying the source. If a conversion fails, inspect the input and output paths; pamtotiff normally reports the first file or format problem on standard error.

3. Choose compression deliberately

The default is an uncompressed TIFF. That is predictable and widely readable, but it can be larger than necessary. Select one compression method when size matters:

$ pamtotiff -flate -output '/path/to/result-flate.tif' '/path/to/source.pnm'
$ pamtotiff -lzw -output '/path/to/result-lzw.tif' '/path/to/source.pnm'
$ file '/path/to/result-flate.tif' '/path/to/result-lzw.tif'

-flate uses the zlib-based compression also used by PNG. -lzw is another available choice on this installation, but a TIFF library on an older system may not provide it. Other supported choices are -none, -packbits, -g3, -g4 and -adobeflate. Group 3 and Group 4 are for bilevel or fax-like data, not ordinary colour photographs. The -2d and -fill options only apply with Group 3.

Checkpoint

Use file, or your receiving application's import test, to confirm that the selected compression is accepted before replacing an original.

4. Control colour output when it matters

PBM and PGM input produce grayscale TIFF. A PPM image containing a few colours may become a paletted TIFF; an image with more than 256 colours becomes RGB. Use -color to force colour output for a PPM image that happens to contain only grey shades. Add -truecolor when you need 24-bit RGB instead of a palette:

$ pamtotiff -color -truecolor -output '/path/to/rgb.tif' '/path/to/source.ppm'
$ file '/path/to/rgb.tif'
/path/to/rgb.tif: TIFF image data, ... PhotometricInterpretation=RGB, ...

These two options can also avoid the extra input pass used to analyse PPM colours. For an ordinary grayscale scan, they add nothing. Do not use -miniswhite or -minisblack on genuinely colour data: those photometric settings are for grayscale images.

5. Add another image only after making a backup

A TIFF can contain multiple images. With the current interface, -append means that the output file must already exist; it does not create a new one.

$ cp --preserve=all '/path/to/existing.tif' '/path/to/existing.tif.bak'
$ pamtotiff -append -output '/path/to/existing.tif' '/path/to/second.pnm'
$ file '/path/to/existing.tif'

This changes the TIFF in place and can make it unsuitable for an application that expects one image. The backup is the recovery path: if the result is wrong, restore it with cp --preserve=all '/path/to/existing.tif.bak' '/path/to/existing.tif'. If the target does not exist, omit -append for the first image.

6. Check the result and common traps

  • If file does not identify a TIFF, check that the input is a valid PNM or PAM and that the output was not truncated by a failed redirection.
  • If an existing TIFF gained an unexpected extra image, remember that -output appends to a non-empty file by default. Convert to a new filename instead.
  • If a colour file looks grayscale, check whether the PPM really contains more than grey values, then retry with -color. Use -truecolor too when a palette is not acceptable.
  • If a very large PPM is slow, pamtotiff may be reading it twice to build a palette. The paired -color -truecolor options can avoid that analysis.
  • Do not assume TIFF variants are interchangeable. The TIFF library controls details of the generated file, so test the actual consumer that will open it.

Done means

  • pamtotiff --version identified the expected Netpbm installation.
  • The output is a TIFF at the intended path, confirmed with file or the receiving application.
  • Compression and colour mode match the consumer's requirements.
  • No original file was overwritten accidentally, and any deliberate append has a recoverable backup.