Home / Alt manpages / pnmnoraw(1)

  • pnmnoraw(1)
  • User command
  • linux

Replace pnmnoraw with Plain PNM Output from Netpbm

You will convert a Netpbm image to plain-text PBM, PGM or PPM output, verify the result, and identify the modern command to use in scripts. On this machine, pnmnoraw is an obsolete compatibility name in Netpbm 11.5.2. Allow about ten minutes. You need the netpbm package and a readable PNM or PAM image.

The name is historical. pnmnoraw was replaced by pnmtoplainpnm, which was later replaced by pamtopnm. The current equivalent is pamtopnm -plain. The option changes the representation written to standard output; it does not resize, sharpen, recolour or otherwise edit the image.

1. Confirm what is installed

Check the compatibility link and the package version before changing a script:

$ command -v pnmnoraw
/usr/bin/pnmnoraw
$ readlink -f /usr/bin/pnmnoraw
/usr/bin/pnmtoplainpnm
$ pamtopnm --version
pamtopnm: Using libnetpbm from Netpbm Version: Netpbm 11.5.2

Your version line can include additional build details. The useful checks are that the command exists and that the installed Netpbm release is reported. The local package here is netpbm 2:11.05.02-1.1build1.

Checkpoint

If command -v pnmnoraw prints nothing, do not assume the command has been removed from every Netpbm installation. Read the local replacement manual with man pnmtoplainpnm and use pamtopnm -plain if pamtopnm is available.

2. Prepare a small input without overwriting anything

Use a new PBM file for a predictable test. This creates a two-row, three-column black-and-white image in the current directory:

$ printf 'P1\n3 2\n0 1 0\n1 0 1\n' > sample.pbm
$ file sample.pbm
sample.pbm: Netpbm image data, size 3 x 2, bitmap, ASCII

The redirection creates or truncates sample.pbm. Replace the name with a new path if that file already contains useful data. No elevated privileges are needed when working in a directory you can write.

3. Run the legacy command once

Pass the input file to pnmnoraw and redirect its standard output to a separate destination:

$ pnmnoraw sample.pbm > sample-plain.pbm
$ sed -n '1,5p' sample-plain.pbm
P1
3 2
010
101

Plain PNM output has a readable header and pixel values. Whitespace may differ between Netpbm releases, so verify the format and dimensions rather than comparing every space. The command returns its converted image on standard output and normally prints no progress message.

Checkpoint

Confirm both the exit status and the output file:

$ printf '%s\n' "$?"
0
$ file sample-plain.pbm
sample-plain.pbm: Netpbm image data, size 3 x 2, bitmap, ASCII

4. Use the supported replacement

For new commands and scripts, write the replacement explicitly:

$ pamtopnm -plain sample.pbm > sample-plain-new.pbm
$ cmp sample-plain.pbm sample-plain-new.pbm
$ file sample-plain-new.pbm
sample-plain-new.pbm: Netpbm image data, size 3 x 2, bitmap, ASCII

cmp should produce no output when both files are byte-for-byte identical on this run. A different but valid plain representation can still describe the same image if a future implementation changes harmless whitespace. If you only need to prove the image is readable, inspect the header with file or pass the result to the next Netpbm program.

pamtopnm is a converter in the opposite direction from many similarly named tools: it reads PAM and writes the suitable PNM type. It also reads PNM input as PAM and can therefore copy a PNM image through. The -plain common option requests the plain-text form. Without it, a normal PBM, PGM or PPM result can be raw, binary output.

5. Avoid confusing plain output with image conversion

The old name suggests no raw output, but it does not mean no processing. It selects the textual PNM encoding. It does not convert a JPEG to PPM by itself, alter dimensions or guarantee that every PAM image can become PBM, PGM or PPM.

pamtopnm chooses the output family from the input depth: depth 1 or 2 produces PBM or PGM depending on the maximum value, while depth 3 or 4 produces PPM. It rejects PAM input whose tuple type, depth or maximum value is not suitable unless you deliberately use -assume. Treat -assume as a data-integrity decision, not a compatibility switch: it tells the program that you have checked the channel data yourself.

If a later program accepts only binary PNM, omit -plain. If it needs text for inspection, fixtures or a source-controlled test file, keep -plain. Do not select the format based on the filename extension; the bytes written to standard output are what matter.

6. Make a safe script change

Replace the old command in a pipeline while keeping its standard-output behaviour:

set -eu
input='/path/to/input.pam'
output='/path/to/output.pnm'
pamtopnm -plain "$input" > "$output"
test -s "$output"
file "$output"

This example still truncates an existing output before conversion starts. For an important file, write to a new temporary destination, inspect it, then replace the old file with a deliberate mv. That replacement is a state-changing operation; do not use sudo unless the destination genuinely requires elevated access, and keep a backup if the old output must be recoverable.

If the converter fails, preserve the input and inspect the diagnostic. Check the path with ls -l, check readability with test -r "$input", and confirm that the input is a PNM or PAM image. A missing file, an unsupported PAM layout and a permissions failure need different fixes. Reinstalling Netpbm will not turn an unsupported image structure into a supported one.

Done means

  • The installed version and compatibility link were checked.
  • pnmnoraw output was verified as plain PNM, with the expected dimensions.
  • New scripts use pamtopnm -plain, not the obsolete name.
  • Plain text was chosen because the next tool or fixture needs it, not because it changes image content.
  • Important outputs are written to a new path before any deliberate replacement.