{"id":"image-x-portable-bitmap","mimeType":"image/x-portable-bitmap","name":"Portable Bitmap","shortName":"PBM","category":"Raster Graphics","extensions":[".pbm"],"description":"The image/x-portable-bitmap MIME type represents the Portable Bitmap (PBM) format, the simplest member of the Netpbm family of image formats. Created in the 1980s by Jef Poskanzer, PBM is designed strictly to store 1-bit monochrome (black and white) images without any compression. It supports two distinct encodings: a human-readable ASCII plaintext version (designated by the 'P1' magic number) where pixels are represented by '0' and '1' characters, and a raw binary version ('P4') that packs eight pixels into a single byte. Because of its extreme simplicity, it is widely used as an intermediary format in Unix-based image processing pipelines and optical character recognition (OCR) workflows.","seo":{"title":"image/x-portable-bitmap MIME Type | Developer Reference for PBM","description":"Complete reference for the image/x-portable-bitmap MIME type: Portable Bitmap (PBM), Netpbm 1-bit monochrome formats, P1 and P4 magic bytes.","faqs":[{"question":"What is a PBM file?","answer":"A PBM (Portable Bitmap) file is a highly simplified 1-bit monochrome raster image format. It is part of the Netpbm project and stores images purely as black and white pixels without any shades of gray or color."},{"question":"Can I open a PBM file in a text editor?","answer":"Yes, if the PBM file was saved using the 'plain' ASCII encoding (indicated by the magic number 'P1'). When opened in a text editor, you will see a grid of '0's (white) and '1's (black) that roughly form the shape of the image."},{"question":"Why is the PBM format still used?","answer":"Despite lacking compression, PBM's absolute simplicity makes it incredibly easy for developers to read, write, and manipulate programmatically. It is often used as a stepping stone or temporary intermediary format in complex command-line image processing or OCR (Optical Character Recognition) software."}]},"index":{"compression":["Uncompressed"],"browserSupport":{"score":1,"label":"None"},"commonUses":["Optical Character Recognition (OCR) Pre-processing","Unix/Linux Command-Line Image Pipelines","Academic Image Processing Teaching"]},"technical":{"magicBytes":{"hex":"50 31 (ASCII) or 50 34 (Binary)","ascii":"P1 or P4"},"container":"Netpbm","compressionAlgorithm":["None"],"colorDepth":["1-bit (Monochrome)"],"transparency":false,"animation":false,"metadata":{"exif":false,"xmp":false,"iccProfile":false},"alphaChannel":false,"progressiveLoading":false,"hdrSupport":false},"history":{"developer":"Jef Poskanzer (Netpbm Project)","released":"1988","specification":"Netpbm PBM 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","bmp","svg"],"convertFrom":["png","jpeg","tiff"]},"developer":{"httpHeaders":[{"header":"Content-Type","value":"image/x-portable-bitmap"}],"htmlAccept":"image/x-portable-bitmap, .pbm","fileDetection":["A PBM file always begins with a 2-byte magic number starting with 'P' (Hex: 50).","The second byte determines the encoding: '1' (Hex: 31) for plain ASCII text, and '4' (Hex: 34) for raw binary.","Following the magic bytes are whitespace-separated ASCII numbers defining the image's width and height. Unlike PGM and PPM formats, a PBM file does not include a 'maximum color value' parameter since it is strictly 1-bit."]},"prosCons":{"pros":["Absolute structural simplicity allows parsers to be written from scratch with just a few lines of code","ASCII encoding allows manual editing and debugging directly within a standard text editor","Serves as a flawless, lossless intermediary for 1-bit raster data like scanned documents or barcodes"],"cons":["Strictly limited to 1-bit monochrome images; cannot natively display shades of gray or color","Lack of compression results in extremely large file sizes, particularly when using the ASCII 'P1' encoding","No support for alpha transparency or modern metadata standards like EXIF"]},"specifications":{"url":"https://netpbm.sourceforge.net/doc/pbm.html","rfc":"","mimeAliases":["image/pbm"]},"developerSnippets":{"python":"import magic\n# Libmagic natively detects PBM files\nprint(magic.from_file('scanned_doc.pbm', mime=True)) # Outputs 'image/x-portable-bitmap'","nodejs":"const fs = require('fs');\n// Manually checking the PBM magic bytes (P1 or P4)\nconst buffer = Buffer.alloc(2);\nconst fd = fs.openSync('scanned_doc.pbm', 'r');\nfs.readSync(fd, buffer, 0, 2, 0);\nfs.closeSync(fd);\nconst isPBM = buffer[0] === 0x50 \u0026\u0026 (buffer[1] === 0x31 || buffer[1] === 0x34);\nconsole.log('Is Portable Bitmap (PBM):', isPBM);","go":"import (\n    \"bytes\"\n    \"net/http\"\n)\n// Native Go HTTP detection does not recognize PBM natively.\n// Check directly for the P1 or P4 signatures:\n// isPBM := len(buf) \u003e= 2 \u0026\u0026 buf[0] == 'P' \u0026\u0026 (buf[1] == '1' || buf[1] == '4')","php":"$mime = mime_content_type('scanned_doc.pbm');\necho $mime; // Standard PHP setups typically return 'image/x-portable-bitmap'"},"relatedFormats":["macpaint"]}
