Home / Alt manpages / pnmtoplainpnm(1)

  • pnmtoplainpnm(1)
  • User command
  • linux

Replace pnmtoplainpnm with pamtopnm -plain

You will convert a PNM image to plain, human-readable PNM format and confirm that the result is valid. The installed pnmtoplainpnm command is a compatibility wrapper, not a separate converter: in Netpbm 11.5.2 it invokes pamtopnm -plain. New scripts should call the replacement directly.

Allow about ten minutes. You need Netpbm installed, a readable PBM, PGM, PPM or PAM image, and a writable working directory. The examples are ordinary user commands. They do not need sudo, and they do not alter the input file.

1. Check the installed Netpbm version

Start by checking which commands are on your path and which package supplied them. This is read-only:

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

The package version and paths can differ on another distribution. The installed library identifies itself as Netpbm 11.5.2 here. Keep this check with a bug report or deployment note, because command behaviour can change between package releases.

Checkpoint

Both commands should resolve, and the package should be the Netpbm installation you intend to use. If pnmtoplainpnm is missing but pamtopnm exists, use the replacement command below.

2. Understand what plain PNM means

PNM is the family covering PBM, PGM and PPM. The plain variants store pixel values as text, with magic numbers such as P1, P2 or P3. That makes them convenient for inspection and small generated fixtures, but usually larger and slower than raw variants such as P6. Plain output is a format choice, not an image-quality improvement.

The old manual says that pnmtoplainpnm was obsoleted in Netpbm 10.23 in July 2004. It remains for backward compatibility and does only the equivalent of pamtopnm -plain. Do not look for extra conversion options on the old command. In particular, it does not resize, recolour or otherwise transform the pixels.

3. Convert an existing image without overwriting it

Give the input path to pamtopnm and redirect standard output to a new destination. Substitute a real input path. The destination is deliberately different from the source:

$ pamtopnm -plain /path/to/input.ppm > /path/to/output-plain.ppm

For a one-off compatibility check, the old spelling is also valid:

$ pnmtoplainpnm /path/to/input.ppm > /path/to/output-plain-compat.ppm

Both commands read the image and write the converted image on standard output. A successful exit status means the program completed the conversion; it does not by itself prove that you wrote to the intended path. Shell redirection truncates an existing destination before the command runs, so do not use an important input path as the output path.

Safety checkpoint

If the destination already matters, choose a fresh name or create the replacement beside it first. If the conversion fails, remove only the incomplete new file after checking its path. The original input remains available because the examples never write to it.

4. Verify the output format and dimensions

Use pnmfile to inspect the result. This does not modify the image:

$ pnmfile /path/to/output-plain.ppm
/path/to/output-plain.ppm: PPM plain, 2 by 1  maxval 255

The wording may vary slightly by Netpbm release. Check for the useful facts: the file is recognised as PNM, it reports the expected width and height, and it says plain rather than raw. You can also inspect the header directly for a small file:

$ sed -n '1,5p' /path/to/output-plain.ppm
P3
2 1
255
255 0 0 0 255 0

The first line identifies a plain colour pixmap. The next line contains dimensions, and the following line is the maximum sample value. Larger images can wrap pixel values differently, so do not compare the exact line layout as a format guarantee. Use pnmfile for the structural check.

5. Prove that the old and new commands match

If you are replacing a script, run both commands to separate temporary outputs and compare them byte for byte:

$ pnmtoplainpnm /path/to/input.ppm > /tmp/input-old-plain.ppm
$ pamtopnm -plain /path/to/input.ppm > /tmp/input-new-plain.ppm
$ cmp -- /tmp/input-old-plain.ppm /tmp/input-new-plain.ppm
$ echo "comparison status: $?"
comparison status: 0

No output from cmp followed by status 0 means the files are identical for that input. The temporary files are ordinary data, so remove them when you have finished checking:

$ rm -- /tmp/input-old-plain.ppm /tmp/input-new-plain.ppm

This cleanup is irreversible, but it affects only the two explicitly named temporary files. Do not broaden the command to a directory or wildcard while adapting it. If you need to retain evidence, copy the files somewhere suitable instead.

6. Handle PAM input and common failures

pamtopnm reads PAM and also accepts PNM as input. For a PAM image, it chooses PBM, PGM or PPM according to the image depth and maximum value. A depth of three or four produces PPM; depth one or two produces PGM or PBM depending on the maximum value. The -plain option affects the output representation, not that selection.

The normal conversion requires a PAM tuple type suitable for PBM, PGM or PPM. The -assume option overrides the tuple-type requirement when you have independently confirmed that the channel data is appropriate. Treat that option as a data-integrity decision, not a general repair switch. It does not override every depth constraint, and using it on unknown input can produce a misleading result.

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

$ ls -l -- /path/to/input.ppm
$ test -r /path/to/input.ppm && echo readable

If the output is empty or pnmfile rejects it, inspect the command's error and rerun to a new destination. Do not replace a known-good image until the new file passes the format and dimension checks. Use elevated privileges only when the file permissions genuinely require them; root will not fix an invalid image or a wrong path.

Done means

  • You identified the installed Netpbm package and version.
  • You understand that pnmtoplainpnm is a compatibility wrapper for pamtopnm -plain.
  • The conversion wrote to a new path and left the input untouched.
  • pnmfile confirmed plain PNM output with the expected dimensions.
  • You used cmp if you needed to verify a script migration.
  • You kept -assume for cases where the input tuple data has been checked.