1.9 KiB
signatures/images
Purpose
Registers magic-byte signatures for image formats with the global signature registry. Covers all major raster and vector image types used on the web and in desktop applications. Each signature is registered as a side effect of importing this module.
Features
- PNG, JPEG, GIF (87a, 89a), WebP, BMP, ICO, TIFF (BE/LE)
- HEIC, HEIF, AVIF (multiple brand variants)
- PSD (Adobe Photoshop), SVG, XCF (GIMP)
- PBM, PGM, PPM, PNM, PFM portable bitmap variants
- Radiance HDR (
.hdr,.rgbe) - OpenEXR high dynamic range images
Usage
This module is imported for its side effects only:
// Automatic registration — all image signatures become available for detection
import "@suaveplan/mime/detection/from-magic-bytes/signatures/images";
import { detectFromMagicBytes } from "@suaveplan/mime/detection/from-magic-bytes/from-magic-bytes";
const pngBytes = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
console.log(detectFromMagicBytes(pngBytes)?.mime); // "image/png"
API Reference
No exported functions. All signatures are registered via registerSignature side effects on module load.
Implementation Notes
HEIC/HEIF/AVIF formats share the ISO Base Media File Format container (like MP4) and are distinguished by their ftyp brand code at bytes 8–11. The startsWith helper checks both the ftyp box header at offset 4 and the brand at offset 8 for each variant. Radiance HDR files use the ASCII header #?RGBE or #?RADIANCE at offset 0.
Coverage
The image signature set covers PNG (89 50 4E 47 0D 0A 1A 0A), JPEG (FF D8 FF), GIF (GIF87a / GIF89a), WebP (RIFF + WEBP subtype), AVIF / HEIC (ISOBMFF ftyp brand inside offset-4 box), BMP, TIFF (II*\0 little-endian and MM\0* big-endian), ICO, and SVG (text-sniffed in a separate stage). ISOBMFF brand matching is done against a curated brand set so AVIF, HEIC, HEIF, and MIAF variants all resolve cleanly.