Home / Alt manpages / pbmtoplot(1)

  • pbmtoplot(1)
  • User command
  • linux

Turn a PBM Bitmap into a Unix plot File with pbmtoplot

You will finish with a Unix plot file generated from a PBM bitmap, while keeping the original image untouched. The guide uses Netpbm 11.5.2, from Debian package netpbm 2:11.05.02-1.1build1, and takes about ten minutes if you already have a PBM file.

You need a shell, the pbmtoplot command, and a readable PBM image. This command writes binary plot data to standard output. It is not a general image viewer, and it does not produce a PNG or a text drawing. No elevated privileges are normally needed.

1. Check the installed command

Confirm which executable your shell will run and record the local Netpbm version:

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

The version output includes build details after the library version. The installed manual defines the command as pbmtoplot [pbmfile]. It lists no options specific to pbmtoplot; common libnetpbm options may also be recognised, but this workflow does not depend on them.

2. Inspect the PBM without changing it

Use file to check that the input looks like a PBM image and note its dimensions:

$ file /path/to/input.pbm
/path/to/input.pbm: Netpbm image data, size = 320 x 200, bitmap, ASCII text

The wording varies with the PBM variant and the installed file database. The useful checks are that the path is the file you intended to convert, it is readable, and its reported type is a bitmap rather than an unrelated file. If the path contains spaces, quote it:

$ test -r "/path/to/my bitmap.pbm" && echo readable
readable

Do not edit or delete the source just because the conversion creates a new format. Keeping the PBM gives you a safe input for a retry.

3. Convert to a new plot file

Choose a destination that does not already contain useful output, then redirect standard output to it:

$ pbmtoplot /path/to/input.pbm > /path/to/output.plot
$ printf 'exit status: %s\n' "$?"
exit status: 0

A zero status means that pbmtoplot completed the conversion. The destination is a binary Unix plot file, so opening it in a text editor is not a meaningful visual check. Confirm that it exists and is non-empty:

$ file /path/to/output.plot
/path/to/output.plot: data
$ test -s /path/to/output.plot && echo 'plot output is non-empty'
plot output is non-empty

file may report only data for this output. That is expected on the tested system; it is not a claim that the file is a portable text format. A later Unix plot consumer is responsible for displaying or processing the result.

4. Use standard input when a pipeline is more convenient

Leave out pbmfile when another command should provide the PBM on standard input. This is useful when the image is already in a pipeline:

$ cat /path/to/input.pbm | pbmtoplot > /path/to/piped-output.plot
$ test -s /path/to/piped-output.plot && echo 'piped conversion completed'
piped conversion completed

The cat is only illustrative. For a simple file, passing the path directly is clearer. Avoid putting untrusted text into a shell command without quoting it, and be especially careful when a pipeline's output is redirected to a predictable shared location.

5. Protect existing output before redirecting

Shell redirection with > truncates the destination before the converter starts. That is an irreversible loss if the file contained the only good result. Use a temporary name in the same directory, verify it, and then replace the destination deliberately:

$ pbmtoplot /path/to/input.pbm > /path/to/output.plot.new
$ test -s /path/to/output.plot.new
$ mv -- /path/to/output.plot.new /path/to/output.plot
$ test -s /path/to/output.plot && echo 'replacement installed'
replacement installed

The final mv changes the directory entry after conversion has succeeded. If the conversion fails, leave the existing output alone and inspect the error. Remove an abandoned temporary file only after checking that it is the one you created:

$ ls -l /path/to/output.plot.new
$ rm -- /path/to/output.plot.new

The rm line is a destructive action. Do not run it if the listing shows the wrong path, and do not use a broad wildcard in its place.

6. Diagnose failed conversions

If the command cannot open the input, check the path and permissions without changing anything:

$ ls -l /path/to/input.pbm
$ test -r /path/to/input.pbm && echo readable || echo 'not readable'

If the file is readable but the conversion still fails, check that it is actually PBM data and not a renamed image of another type. A malformed or truncated PBM needs to be repaired or regenerated by the tool that created it. pbmtoplot does not provide a reverse command: the installed manual specifically notes that there is no plottopbm transformation.

Do not add guessed flags for dimensions, output format or scaling. The local manual does not define any pbmtoplot-specific options, and the tested command converts the PBM supplied rather than asking for a resize. If you need a different bitmap, create that input with an appropriate Netpbm converter first, then run this command.

Done means

  • pbmtoplot is installed and its local Netpbm version is known.
  • The source is a readable PBM bitmap and remains unchanged.
  • The command exits successfully and creates a non-empty Unix plot file.
  • Standard input is used only when it makes the pipeline clearer.
  • Existing output is protected from shell redirection truncation.
  • You know that displaying the binary plot file requires a separate Unix plot consumer.