Portable bitmap format (black and white)

.pbm · Images

PBM (Portable Bitmap) is probably the simplest image format still in daily use: one bit per pixel, black or white, behind a header a few characters long. It belongs to the Netpbm family together with PGM for greyscale and PPM for colour. People rarely send each other PBM files. Programs produce them: Linux scanning tools, OCR and fax pipelines, the vectorizer potrace, university programming assignments and scripts that simply needed the easiest image format to write.

Origin

Jef Poskanzer designed PBM in the 1980s so that a bitmap could travel inside an e-mail message, in an era without attachments. That is why the original variant is plain ASCII text. In 1988 he released Pbmplus, a set of converters between PBM and other formats, and by the end of that year added PGM and PPM. The last Pbmplus release came out on 10 December 1991. In 1993 the project continued as Netpbm, which Bryan Henderson has maintained since 1999. There is no ISO standard and no MIME type registered with IANA; the reference is the Netpbm specification and the usual type is image/x-portable-bitmap.

How a PBM file works

  • Plain PBM (P1) stores each pixel as the character 0 or 1. The text P1 3 2 1 0 1 0 1 0 is a complete, valid 3 × 2 image. Lines may not be longer than 70 characters.
  • Raw PBM (P4) packs eight pixels into a byte, every row padded to whole bytes. The header stays text: magic number, width, height, optional comments after #.
  • 1 means black and 0 means white. Most other formats, including WBMP, do it the other way round. Home-made decoders that miss this produce a negative.
  • No compression, no palette, no dpi value, no metadata, no transparency. An A4 page at 300 dpi (2480 × 3508 pixels) takes about 1.1 MB as P4 and at least eight times more as P1.
  • Since 2000 a raw file may contain several images one after another, but most programs read only the first.

How to open a PBM file

  • Windows: IrfanView, XnView MP, GIMP or Photoshop. The built-in Photos app does not read PBM.
  • macOS: GIMP or XnView MP.
  • Linux: most image viewers in GNOME and KDE read the Netpbm formats directly, and the Netpbm package converts them on the command line (pnmtopng).
  • A plain P1 file also opens in any text editor, where you can see the zeros and ones.

Common PBM problems

The PBM image comes out inverted

The program or your own code treats 1 as white. In PBM, 1 is black.

A photo became black blobs after converting to PBM

PBM has only two values. Our converter turns the image to grey, stretches the contrast and splits it at 50 % brightness, without dithering. That works well for text, signatures, line drawings and QR codes, poorly for photographs. For photos keep PNG or use greyscale PGM.

The .pbm file starts with P2, P5 or P6

That is greyscale or colour data with the wrong extension, common with tools that write any Netpbm type. Our converter reads all Netpbm variants regardless of the extension.

Another program rejects the PBM my code wrote

The usual causes are missing whitespace after the height, rows in P4 not padded to whole bytes, or a comment placed inside the pixel data.

Converting PBM

PBM to PNG, TIFF or GIF is lossless and gives a file that every program opens. PBM to PDF is the quick way to turn a scanned page into a document. PBM to SVG traces the pixels into vector curves. In fact, when you convert any raster image to SVG with us, the converter first makes a black-and-white PBM and traces that. In the other direction, converting to PBM is the reliable way to force pure black and white, for example before preparing a 1-bit logo for a label printer as PCX.

PBM at a glance

AuthorJef Poskanzer; maintained by the Netpbm project
First release1980s; Pbmplus 1988, Netpbm 1993
SpecificationNetpbm documentation, no ISO standard
TypeRaster image, 1 bit per pixel
CompressionNone
VariantsP1 (text), P4 (binary)
Typical useScanning and OCR pipelines, vectorizing, teaching, scripts

Specification and history: PBM format specification and history of Netpbm.

We can convert PBM into

Documents

PDF TXTPDF/A

Images

JPG PNGWEBP GIF TIFFHEICAVIFJXLPSDICOAAIAPNGARTAVS BMP CINCURDCMDCXDDSDPXFF FITSFL32 HDRHRZJP2JBIGJNGJPCMNGMTVOTBPALMPAMPCD PCXPFMPGMPGXPHMPICTPPMPSBPTIFQOIRASRGFSGISIXELSUN TGAVICARVIFFVIPS WBMPXBMXPMXWD

Vector images

SVG EPSEMF PSFXGHPGLPOVSIFSVGZWMFXAML

eBooks

EPUB MOBI AZW3 FB2CBZDJVUHTMLZ LIT LRF OEB PDB TCRTXTZCB7CBT