Skip to content

Portable Graymap Graphic (.pgm)

.pgm file signature | image/x-portable-graymap

Portable Graymap Graphic

Safe

Magic Bytes

Offset 0
50 35 0A

Sources: Wikipedia, Gary Kessler

All Known Signatures

3 signature variants are documented for .pgm files across multiple sources.

Hex Signature Offset Sources
50 35 0A 0 Wikipedia, Gary Kessler
50 32 0 Apache Tika
50 32 0A 0 Wikipedia

Extension

.pgm

MIME Type

image/x-portable-graymap

Byte Offset

0

Risk Level

Safe

Validation Code

How to validate .pgm files in Python

Python
def is_pgm(file_path: str) -> bool:
    """Check if file is a valid PGM by magic bytes."""
    signature = bytes([0x50, 0x35, 0x0A])
    with open(file_path, "rb") as f:
        return f.read(3) == signature

How to validate .pgm files in Node.js

Node.js
function isPGM(buffer: Buffer): boolean {
  const signature = Buffer.from([0x50, 0x35, 0x0A]);
  return buffer.subarray(0, 3).equals(signature);
}

How to validate .pgm files in Go

Go
func IsPGM(data []byte) bool {
    signature := []byte{0x50, 0x35, 0x0A}
    if len(data) < 3 {
        return false
    }
    return bytes.Equal(data[:3], signature)
}

API Endpoint

GET /api/v1/pgm
curl https://filesignature.org/api/v1/pgm

See the full API documentation for all endpoints and parameters.

Frequently Asked Questions

What is a .pgm file?

A .pgm file is a Portable Graymap Graphic file. Portable Graymap Graphic

What are the magic bytes for .pgm files?

The magic bytes for Portable Graymap Graphic files are 50 35 0A at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.

How do I validate a .pgm file?

To validate a .pgm file, read the first bytes of the file and compare them against the known magic bytes (50 35 0A) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.

What is the MIME type for .pgm files?

The primary MIME type for .pgm files is image/x-portable-graymap.

Is it safe to open .pgm files?

Portable Graymap Graphic (.pgm) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.