{"id":"image-x-portable-graymap","mimeType":"image/x-portable-graymap","name":"Portable Graymap","shortName":"PGM","category":"Raster Graphics","extensions":[".pgm"],"description":"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.","seo":{"title":"image/x-portable-graymap MIME Type | Developer Reference for PGM","description":"Complete reference for the image/x-portable-graymap MIME type: Portable Graymap (PGM), Netpbm grayscale formats, P2 and P5 magic bytes, and scientific imaging.","faqs":[{"question":"What is a PGM file?","answer":"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."},{"question":"What is the difference between PGM and PBM?","answer":"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)."},{"question":"How do I open a PGM file?","answer":"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."}]},"index":{"compression":["Uncompressed"],"browserSupport":{"score":1,"label":"None"},"commonUses":["Computer Vision and Machine Learning Pre-processing","Scientific and Medical Image Processing","Unix/Linux Command-Line Image Pipelines"]},"technical":{"magicBytes":{"hex":"50 32 (ASCII) or 50 35 (Binary)","ascii":"P2 or P5"},"container":"Netpbm","compressionAlgorithm":["None"],"colorDepth":["8-bit (Grayscale)","16-bit (Grayscale)"],"transparency":false,"animation":false,"metadata":{"exif":false,"xmp":false,"iccProfile":false},"alphaChannel":false,"progressiveLoading":false,"hdrSupport":true},"history":{"developer":"Jef Poskanzer (Netpbm Project)","released":"1988","specification":"Netpbm PGM Format Specification"},"browserSupport":{"chrome":false,"chromeVersion":"None","firefox":false,"firefoxVersion":"None","safari":false,"safariVersion":"None","edge":false,"edgeVersion":"None","internetExplorer":false},"softwareSupport":[{"name":"Netpbm (Command-line tools)","logo":""},{"name":"ImageMagick","logo":"image-magic.webp"},{"name":"GIMP","logo":"gimp.svg"},{"name":"XnView","logo":""}],"conversion":{"convertTo":["png","tiff","jpeg"],"convertFrom":["png","jpeg","tiff","ppm"]},"developer":{"httpHeaders":[{"header":"Content-Type","value":"image/x-portable-graymap"}],"htmlAccept":"image/x-portable-graymap, .pgm","fileDetection":["A PGM file always begins with a 2-byte magic number starting with 'P' (Hex: 50).","The second byte determines the encoding: '2' (Hex: 32) for plain ASCII text, and '5' (Hex: 35) for raw binary.","Following the magic bytes are whitespace-separated ASCII numbers defining the image's width, height, and the maximum gray value (usually 255 or 65535)."]},"prosCons":{"pros":["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"],"cons":["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"]},"specifications":{"url":"https://netpbm.sourceforge.net/doc/pgm.html","rfc":"","mimeAliases":["image/pgm"]},"developerSnippets":{"python":"import magic\n# Libmagic natively detects PGM files and correctly identifies them based on the P2/P5 signature\nprint(magic.from_file('scan.pgm', mime=True)) # Outputs 'image/x-portable-graymap'","nodejs":"const fs = require('fs');\n// Manually checking the PGM magic bytes (P2 or P5)\nconst buffer = Buffer.alloc(2);\nconst fd = fs.openSync('scan.pgm', 'r');\nfs.readSync(fd, buffer, 0, 2, 0);\nfs.closeSync(fd);\nconst isPGM = buffer[0] === 0x50 \u0026\u0026 (buffer[1] === 0x32 || buffer[1] === 0x35);\nconsole.log('Is Portable Graymap (PGM):', isPGM);","go":"import (\n    \"bytes\"\n    \"net/http\"\n)\n// Native Go HTTP detection does not recognize PGM natively.\n// Check directly for the P2 or P5 signatures:\n// isPGM := len(buf) \u003e= 2 \u0026\u0026 buf[0] == 'P' \u0026\u0026 (buf[1] == '2' || buf[1] == '5')","php":"$mime = mime_content_type('scan.pgm');\necho $mime; // Standard PHP setups typically return 'image/x-portable-graymap'"},"relatedFormats":["png"]}
