PGM file format: what it is and how to use it
PGM is the Portable Graymap, the Netpbm grayscale member, storing intensity-only images in a trivially parsed format. Learn when to use it and what to choose instead.
-
No uploadsFiles stay on your device
-
Batch processingHandle multiple files at once
-
100% privateNo sign-up, no tracking
What is a PGM file?
A .pgm file is a grayscale image in Portable Graymap, the middle child of the Netpbm family: a header (P2 ASCII or P5 raw binary), a max value, then intensity-only pixels. One channel, no color, no compression, the simplest possible grayscale interchange, which is exactly why vision libraries and scripts still emit it.
When should you use PGM?
- Grayscale pipelines: depth maps, masks, sensor output and gray scans.
- Vision research: OpenCV-era datasets and algorithms often use it.
- Scripted processing: readable and writable in a dozen lines.
When is another format a better fit?
For color you need PPM; for arbitrary channels PAM; for real images PNG: same grayscale data, compressed and universally readable. PGM is a pipeline intermediate, nothing more.
The short version: PGM is the grayscale Netpbm member: fine inside a processing script. Convert to PNG for anything else.
How to open a PGM file
On Windows
Double-click the file, or open it with GIMP.
On macOS
XnView opens PGM files on macOS.
In your browser
Open PGM files right in a browser tab or with the dexrr viewer. No install, no upload.
Also opens in
-
Netpbm tools
-
ImageMagick -
GIMP
-
XnView
View PGM files
A quick preview or a new format. No install, no upload.
PGM technical details
- Full name
- Portable Graymap
- Extensions
- .pgm
- MIME type
-
image/x-portable-graymap - Magic bytes
-
50 32 / 50 35 (P2/P5) - Compression
- None (uncompressed)
- Developer
- Jef Poskanzer (Netpbm)
- Specification
- netpbm.sourceforge.net
PGM questions, answered
How do I open a .pgm file?
Netpbm tools, ImageMagick, GIMP, OpenCV and FFmpeg read it; general viewers usually do not. dexrr displays and converts pgm files directly in your browser.
Can I convert PGM files online?
Yes, dexrr converts pgm locally in your browser: PGM to PNG for normal use.
Is PGM better than PNG?
Only in parsing simplicity. PNG stores the same grayscale compressed and readable everywhere. PGM is a script format, PNG a real one.
What is the difference between P2 and P5?
The magic number. P2 stores gray values as ASCII numbers, P5 as raw binary bytes. Same image, different encoding.
Is the PGM format outdated?
Stable and niche: a Unix-pipe artifact kept alive by vision tools and scripts.