Home / Alt manpages / pbmtowbmp(1)

  • pbmtowbmp(1)
  • User command
  • linux

Convert a PBM Image to WBMP with pbmtowbmp

You will finish with a wireless bitmap file made from a PBM image, then check it by converting it back to PBM. The examples use the Netpbm 11.5.2 build installed on this machine, packaged as netpbm 2:11.05.02-1.1build1.

Allow about ten minutes. You need a readable PBM file and a shell. The conversion itself normally needs no elevated privileges. You do not need sudo, a running service, or a network connection.

1. Check the installed command

Confirm that the command is available and record the version before putting it in a script. These are read-only checks:

$ command -v pbmtowbmp
/usr/bin/pbmtowbmp
$ pbmtowbmp --version
pbmtowbmp: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
pbmtowbmp: Built from source dated 2024-03-31 09:09:47
pbmtowbmp: Built by Debian
pbmtowbmp: BSD defined
pbmtowbmp: RGB_ENV='RGBDEF'
pbmtowbmp: RGBENV= 'RGBDEF' (env vbl is unset)

The version output contains build details as well as the version number, so the exact wording can vary. The useful checkpoint is that the command resolves to the intended Netpbm installation. The installed package can also be queried on Debian or Ubuntu:

$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1

pbmtowbmp has no options specific to this conversion. Its syntax is a single optional input file. With no file, the input is read from standard input, which is useful in a pipeline but easy to miss when a command appears to wait for input.

2. Inspect the PBM before converting it

Check the input path, permissions and detected format without changing the file:

$ test -r /path/to/input.pbm && echo readable
readable
$ file /path/to/input.pbm
/path/to/input.pbm: Netpbm image data, size = 320 x 240, bitmap

The dimensions in your output will differ. PBM is a black-and-white bitmap format, not a greyscale or colour image. If file reports another format, convert that image to PBM with an appropriate Netpbm or image tool first. Do not rename a PNG or JPEG to .pbm; the converter reads the file contents, not the suffix.

Checkpoint: keep the original input in place. This command only reads it, and the output should have a different name.

3. Write a WBMP file without destroying an old output

Redirect standard output to a new destination:

$ pbmtowbmp /path/to/input.pbm > /path/to/output.wbmp
$ test -s /path/to/output.wbmp && echo 'WBMP output is non-empty'
WBMP output is non-empty

A successful exit status means the program produced output for the input it could read. It does not tell you whether an old file was overwritten. Shell redirection opens the destination before pbmtowbmp runs, so an existing output.wbmp is truncated immediately. This is the main destructive trap in a simple conversion command.

For a destination that might already exist, write a temporary file in the same directory and replace the old file only after verification:

$ pbmtowbmp /path/to/input.pbm > /path/to/output.wbmp.new
$ test -s /path/to/output.wbmp.new
$ mv /path/to/output.wbmp.new /path/to/output.wbmp

The mv step changes the destination, so check the name carefully first. If conversion fails, leave the original output untouched and remove only the incomplete .new file when you have confirmed that it is not needed. If you made a replacement by mistake, recovery requires a backup or another copy of the previous WBMP; the converter cannot reconstruct an overwritten file.

4. Convert standard input in a pipeline

Use the optional input filename when you have a file. Omit it when another command supplies PBM data on standard input:

$ cat /path/to/input.pbm | pbmtowbmp > /path/to/output.wbmp
$ test -s /path/to/output.wbmp && echo 'pipeline conversion completed'
pipeline conversion completed

For a normal file, the direct form is clearer because an input error names the file you selected. In a longer pipeline, check each producer separately if the result is empty. Avoid using a command that emits text diagnostics on standard output as the PBM producer, because those bytes would become part of the binary WBMP stream.

5. Verify the WBMP with a round trip

WBMP is a binary format, so do not use cat or a text editor to inspect it. The companion wbmptopbm command can read a type 0 WBMP and emit a PBM image:

$ wbmptopbm /path/to/output.wbmp > /tmp/output-roundtrip.pbm
$ file /tmp/output-roundtrip.pbm
/tmp/output-roundtrip.pbm: Netpbm image data, size = 320 x 240, rawbits, bitmap
$ test -s /tmp/output-roundtrip.pbm && echo 'round trip produced PBM'
round trip produced PBM

Compare the dimensions with the original. The output may use a different PBM encoding, such as rawbits instead of ASCII text, while still representing the same bitmap. For a stronger check, use a separate image comparison tool available on your system or inspect both images with a trusted viewer. Keep the original PBM until this check is complete.

6. Know the format boundary

The manual limits this program to WBMP type 0. That is the type specified by WAP 1.1 and the only type this tool can generate. It is not a general converter for every WBMP variant. The reverse tool has the same type 0 limitation, so a round trip with wbmptopbm is a check of this Netpbm workflow, not proof that an arbitrary WBMP file is supported.

If conversion fails while reading the input, check the path, permissions and PBM header first. An empty file is not a valid PBM and produces a non-zero exit status. If a downstream viewer rejects the result, confirm that it expects WBMP type 0 and that the output is non-empty before changing permissions or running anything as root.

Done means

  • The installed command and Netpbm package version were checked.
  • The input is a readable PBM with dimensions you understand.
  • The WBMP was written to a deliberate destination without needlessly destroying an existing file.
  • A non-empty result was converted back with wbmptopbm and its dimensions were checked.
  • You know the result is WBMP type 0 and have kept the original PBM for recovery.