Free webp to jpg
PGM

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.

Raster Graphics ✦ HDR Production Ready

Technical Specifications

MIME Type
image/x-portable-graymap
Extensions
.pgm
Container
Netpbm
Compression
Uncompressed
Algorithms
None
Color Depth
8-bit (Grayscale), 16-bit (Grayscale)
Metadata
None
Capabilities
Transparency
Animation
Progressive Loading
Alpha Channel
HDR Support
Official Specification
Aliases: image/pgm

Magic Bytes & HTTP Headers

File Signature (Magic Bytes)
50 32 (ASCII) or 50 35 (Binary)
ASCII: P2 or P5
HTTP Headers
Content-Type: image/x-portable-graymap
HTML Accept Attribute
accept="image/x-portable-graymap, .pgm"

Browser Support Matrix

Browser Status Min Version
Chrome Chrome
Not Supported
Firefox Firefox
Not Supported
Safari Safari
Not Supported
Edge Edge
Not Supported
Internet Explorer Internet Explorer
Not Supported Legacy

Advantages & Limitations

Advantages
  • 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
Limitations
  • 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

import magic
# Libmagic natively detects PGM files and correctly identifies them based on the P2/P5 signature
print(magic.from_file('scan.pgm', mime=True)) # Outputs 'image/x-portable-graymap'
const fs = require('fs');
// Manually checking the PGM magic bytes (P2 or P5)
const buffer = Buffer.alloc(2);
const fd = fs.openSync('scan.pgm', 'r');
fs.readSync(fd, buffer, 0, 2, 0);
fs.closeSync(fd);
const isPGM = buffer[0] === 0x50 && (buffer[1] === 0x32 || buffer[1] === 0x35);
console.log('Is Portable Graymap (PGM):', isPGM);
import (
    "bytes"
    "net/http"
)
// Native Go HTTP detection does not recognize PGM natively.
// Check directly for the P2 or P5 signatures:
// isPGM := len(buf) >= 2 && buf[0] == 'P' && (buf[1] == '2' || buf[1] == '5')
$mime = mime_content_type('scan.pgm');
echo $mime; // Standard PHP setups typically return 'image/x-portable-graymap'

File Detection Steps

How to programmatically detect a image/x-portable-graymap file by reading its raw bytes:

  1. 1 A PGM file always begins with a 2-byte magic number starting with 'P' (Hex: 50).
  2. 2 The second byte determines the encoding: '2' (Hex: 32) for plain ASCII text, and '5' (Hex: 35) for raw binary.
  3. 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

N
Netpbm (Command-line tools)
ImageMagick ImageMagick
GIMP GIMP
X
XnView

Conversion Tools

Share & Embed

Markdown Badge
PGM Format Badge
[![PGM Format](https://freewebptojpg.com/mime/image/pgm/badge.svg)](https://freewebptojpg.com/mime/image/pgm)
Interactive iframe Widget
<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
Free to use
No auth required
CORS enabled
Use from any domain
Cached 24h
Cache-Control headers set

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.

Related Formats

Share this format