Introduction
The Netpbm formats are three very simple uncompressed image formats from Jef
Poskanzer's Pbmplus toolkit of the late 1980s, now maintained as
Netpbm. PBM holds black and white
bitmaps, PGM greyscale images and PPM colour images. .pnm is used for
any of the three.
They have no compression and almost no metadata, which makes them easy to write from any program. They are common as a go-between in image processing pipelines, in teaching and in test suites.
Structure
Each file starts with a two-character magic number that gives the type and encoding:
P1 to P3 for plain (ASCII) PBM, PGM and PPM, and
P4 to P6 for the raw (binary) versions. After it come the
width, the height and, for PGM and PPM, the maximum sample value, all written as
decimal text separated by whitespace. A # starts a comment that runs to
the end of the line.
A single whitespace character ends the header, and the pixels follow row by row from the top. In the binary versions PBM packs eight pixels into a byte, and PGM and PPM use one byte per sample, or two big-endian bytes when the maximum value is above 255.
P3
# a 2 by 1 colour image
2 1
255
255 0 0 0 0 255
Links
Software
- Netpbm (Windows, macOS, Linux)
- GIMP (Windows, macOS, Linux)
- IrfanView (Windows)
- XnView MP (Windows, macOS, Linux)
- ImageMagick (Windows, macOS, Linux)
Developers
Reference
- PPM format specification, Netpbm, with links to the PBM and PGM pages