Replace bmptoppm with bmptopnm
Your old script still calls bmptoppm, and it still works, but only because the name is now a link to bmptopnm. This guide converts a BMP with the current command, checks the output type instead of guessing it, and keeps an existing output safe while you test. Allow about ten minutes. You need a shell, a readable BMP file and the netpbm package.
The route
Jump straight to the step you need, or tick off Done means at the end.
It describes Netpbm 11.5.2 from Debian package 2:11.05.02-1.1build1. The installed bmptoppm is a symbolic link to bmptopnm, so new scripts should use bmptopnm directly.
1. Confirm which command you have
Check both names before changing a script or troubleshooting an image:
$ command -v bmptoppm
/usr/bin/bmptoppm
$ command -v bmptopnm
/usr/bin/bmptopnm
$ ls -l "$(command -v bmptoppm)"
lrwxrwxrwx ... /usr/bin/bmptoppm -> bmptopnm
Permissions, date and exact link formatting can differ. What matters is that both commands resolve and the old name points at the replacement. Check the implementation version without converting an image:
$ bmptopnm --version
bmptopnm: Using libnetpbm from Netpbm Version: 11.5.2
...
The remaining version lines are build details.
Warning
If bmptopnm is missing, stop and install or repair Netpbm through your normal package-management process. Do not create a hand-written replacement link in /usr/bin.
2. Convert a BMP to a Netpbm image
Pass the input filename to bmptopnm and redirect standard output to a new destination:
$ bmptopnm /path/to/input.bmp > /path/to/output.pnm
$ printf 'converter status: %s\n' "$?"
converter status: 0
A status of 0 means the converter completed. The output may be PBM, PGM or PPM, and that is the main difference from the historical name: bmptopnm picks a more specific format when the BMP data allows it. A black-and-white image can produce PBM, and a grayscale image can produce PGM.
Inspect the result before passing it to another program:
$ file /path/to/output.pnm
/path/to/output.pnm: Netpbm image data, size = 32 x 32, rawbits, bitmap
$ head -c 2 /path/to/output.pnm
P4
The exact file wording varies. The magic bytes identify the format:
P4: PBM.P5: PGM.P6: PPM.
Checkpoint
The magic bytes match the format you expected. Do not name every output .ppm unless the next tool genuinely accepts that mismatch.
3. Protect an existing output while testing
Shell redirection with > truncates its destination before the converter starts. That is destructive if the destination already holds a useful image. Use a temporary name in the same directory, then replace the old file only after checking the new one:
$ bmptopnm /path/to/input.bmp > /path/to/output.pnm.new
$ status=$?
$ if [ "$status" -eq 0 ] && [ -s /path/to/output.pnm.new ]; then
> file /path/to/output.pnm.new
> mv /path/to/output.pnm.new /path/to/output.pnm
> else
> printf 'conversion failed; original output was left alone\n' >&2
> rm -f /path/to/output.pnm.new
> exit "$status"
> fi
/path/to/output.pnm.new: Netpbm image data, ...
Warning
The mv is the state-changing step. If you want an easy rollback, copy the old output first:
$ cp --preserve=all /path/to/output.pnm /path/to/output.pnm.bak
$ mv /path/to/output.pnm.bak /path/to/output.pnm
Recovery
The second command restores the backup, provided you have not changed it. Remove a backup only after checking the replacement, and only when you accept that deleting it is irreversible.
4. Read the BMP header diagnostics
Use -verbose to see what the converter read from the header:
$ bmptopnm -verbose /path/to/input.bmp > /path/to/output.pnm
bmptopnm: BMP image header says:
bmptopnm: Width: 32 pixels
bmptopnm: Height: 32 pixels
bmptopnm: Bits per pixel in raster: 1
bmptopnm: WRITING PBM IMAGE
Header details and wording depend on the input. The messages go to standard error, while the converted image still goes to standard output. Keep the redirection in place or binary image data will spill into your terminal.
5. Handle failures without guessing
A missing or unreadable input is a path or permission problem, not a reason to run the converter as root:
$ test -r /path/to/input.bmp && echo readable
$ ls -l /path/to/input.bmp
$ bmptopnm /path/to/input.bmp > /tmp/output.pnm
$ printf 'converter status: %s\n' "$?"
- Restricted files: use
sudoonly if the file or destination is deliberately restricted and your system policy permits that access. Ordinary image conversion should run as your normal user. - Unsupported compression: if the command reports a BMP compression mode it cannot convert, keep the original file and use a tool that supports that encoding.
- Exit status 0 is not proof of a good image. Check the reported dimensions and inspect the result with a trusted viewer or a later converter.
- Old scripts: replace
bmptoppmwithbmptopnmso the intended command is clear. Review any downstream code that assumes a PPM magic number, because the replacement can deliberately emit PBM or PGM.
Done means
- Command resolved.
bmptopnmpoints at the installed Netpbm implementation and its version is known. - Conversion worked. A readable BMP converted with status 0 to a non-empty PBM, PGM or PPM file.
- Format checked. You read the output magic bytes instead of inferring them from the filename.
- Output protected. Existing output survived redirection truncation during testing.
- Old name understood.
bmptoppmis a compatibility name, and downstream PPM-only assumptions need review.