PPM to PNG
Nothing opens a .ppm. Not your image viewer, not your browser, not the thing you were about to paste it into — the format predates the idea that anyone but a program would want to look at it. This reads all seven Netpbm variants and hands you a PNG.
Drop Netpbm files here
.ppm, .pgm, .pbm, .pnm, .pam — multiple files allowed
What it reads
All six of the classic magic numbers, plus PAM. The label under each result says which one your file turned out to be, along with its bit depth and maximum value — useful on its own when you have a file and no idea what wrote it.
- P6 — PPM, binary RGB. The common one. Three bytes per pixel, or six at 16-bit.
- P5 — PGM, binary greyscale. One byte per pixel, or two at 16-bit. Depth maps and scientific output usually land here.
- P4 — PBM, binary bitmap. One bit per pixel, eight to a byte, each row padded out to a whole byte. That padding is where hand-written readers get it wrong on any width that is not a multiple of eight.
- P3, P2, P1 — the ASCII forms. Same three images with every value spelled out as decimal text. Three to four times the size, and readable in a text editor, which is why coursework asks for them.
- P7 — PAM. The extended format, with a keyword header and an arbitrary channel count. It is the only member of the family that can carry alpha, and transparency is preserved here:
DEPTH 2is grey plus alpha,DEPTH 4is RGB plus alpha.
The details that break other readers
Netpbm looks like it can be parsed with three calls to readline, and it cannot.
Three things in the specification bite:
- Comments can appear anywhere in the header, including between the width and
the height.
P3\n2 # width\n2\n255\nis a legal 2 × 2 image. The header is read as whitespace-separated tokens with comments skipped at any point, not as lines. - Exactly one whitespace character separates a binary header from its raster. Skipping whitespace greedily eats the first sample of any image whose top-left pixel happens to be 0x20, 0x0A or 0x09 — a bug that shows up as a one-pixel colour shift on some files and not others, which is a miserable thing to chase.
- P1 and P4 invert. In the bitmap formats, 1 means black and 0 means white, the opposite of every other format in the family and of the intuition. A reader that gets this wrong produces a perfect negative.
16-bit samples are big-endian and are scaled down to 8-bit for the PNG, since a
canvas is 8-bit per channel. A maximum value that is not 255 — 15,
1023, 4095 — is scaled properly rather than clipped, which is the
other common way a converted PGM comes out almost black.
Errors you might see
Every file is decoded on its own, so one bad file in a batch does not stop the rest, and the status line names it. Truncated means the header promises more pixels than the file contains — usually a partial download or a pipe that was cut off; the numbers tell you how much arrived. Not a Netpbm file means the first token is not one of the magic numbers, which most often means the extension is wrong.
Privacy
100% client-side. The file is decoded and re-encoded in your browser; nothing is uploaded.
Related tools
- PNG to PPM / PGM / PBM — the other direction, all six variants.
- Image inspector — dimensions, colour depth and metadata of what comes out.
- PNG to TGA and PNG to BMP — the other formats that predate the web.
- Colour count — how many distinct colours the decoded image actually has.