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
Netpbm also defines a fourth, more general format, PAM, with the magic number
P7 and a named-line header. It is covered on its own page below.
In this reference
Not described
The header, raster and PAM pages follow the Netpbm documentation. These gaps remain.
Known, not yet covered
- Viewer: there is no Netpbm plugin yet, so a dropped file is not opened in the explorer.
- Reference: the media types
image/x-portable-bitmapandimage/x-portable-graymapare stated from general knowledge, not from a source read for this site, and the.pamextension has no record of its own (see PAM).
Links
Software
- Netpbm – the toolkit the formats come from, with hundreds of command-line converters and filters (Windows, macOS, Linux)
- GIMP – free image editor that opens and saves PPM, PGM and PBM (Windows, macOS, Linux)
- IrfanView – image viewer and converter (Windows)
- XnView MP – image viewer and batch converter (Windows, macOS, Linux)
- ImageMagick – command-line tools that convert to and from the Netpbm formats (Windows, macOS, Linux)
Developers
Reference
- PPM format specification – Netpbm’s description of PPM
- PGM format specification – Netpbm’s description of PGM
- PBM format specification – Netpbm’s description of PBM
- PAM format specification – Netpbm’s description of PAM