Portable Graymap
image/x-portable-graymap
Released 1988
· by Jef Poskanzer (Netpbm Project)
The image/x-portable-graymap MIME type represents the Portable Graymap (PGM) format, a grayscale image format belonging to the Netpbm family. Created by Jef Poskanzer in the late 1980s, PGM was designed as an ultra-simple, uncompressed format to facilitate the exchange of grayscale images between different platforms and command-line tools. It stores raster data using one of two encodings: a human-readable ASCII plaintext version (designated by the 'P2' magic number) where pixel intensities are written as numbers, and a more efficient raw binary version ('P5'). Because it can support high bit depths (up to 16-bit per channel) while remaining incredibly easy to parse, it is widely used in scientific imaging, computer vision research, and intermediary data processing pipelines.
Technical Specifications
.pgm
None
image/pgm
Magic Bytes & HTTP Headers
P2 or P5
Browser Support Matrix
| Browser | Status | Min Version |
|---|---|---|
|
|
Not Supported | — |
|
|
Not Supported | — |
|
|
Not Supported | — |
|
|
Not Supported | — |
|
|
Not Supported | Legacy |
Advantages & Limitations
- Extremely simple format allows custom parsers to be written from scratch in minimal time
- Supports 16-bit precision, making it highly valuable for scientific, medical, and height-map data where 8-bit precision is insufficient
- ASCII encoding ('P2') allows manual editing and visual inspection of pixel values directly within a text editor
- Strictly limited to grayscale; cannot display color
- Lack of compression results in massive file sizes, making it entirely impractical for web delivery or consumer storage
- Does not support alpha transparency or modern metadata structures
Developer Code Snippets
File Detection Steps
How to programmatically detect a image/x-portable-graymap
file by reading its raw bytes:
- 1 A PGM file always begins with a 2-byte magic number starting with 'P' (Hex: 50).
- 2 The second byte determines the encoding: '2' (Hex: 32) for plain ASCII text, and '5' (Hex: 35) for raw binary.
- 3 Following the magic bytes are whitespace-separated ASCII numbers defining the image's width, height, and the maximum gray value (usually 255 or 65535).
Software Support
ImageMagick
Conversion Tools
Share & Embed
[](https://freewebptojpg.com/mime/image/pgm)
<iframe src="https://freewebptojpg.com/mime/image/pgm/embed" width="100%" height="280" style="border:1px solid #cbd5e1;border-radius:8px;" title="PGM Specs"></iframe>
JSON API
All data on this page is available as a free, open JSON API. Use it in your project, documentation, or tooling.
GET https://freewebptojpg.com/mime/image/pgm.json
Open JSON
Frequently Asked Questions
What is a PGM file?
A PGM (Portable Graymap) file is an uncompressed grayscale image format. Part of the Netpbm suite, it represents pixels purely as shades of gray, ranging from black to white.
What is the difference between PGM and PBM?
While PBM (Portable Bitmap) is strictly 1-bit monochrome (black or white only), PGM supports varying shades of gray. A PGM file includes a 'maxval' parameter in its header, which defines the maximum white value (often 255 for 8-bit or 65535 for 16-bit grayscale).
How do I open a PGM file?
Standard web browsers do not support PGM files. To open them, you can use image editing software like Adobe Photoshop, GIMP, or command-line utilities like ImageMagick and the Netpbm suite.