Bitmap to Data URI Converter
Convert BMP, PNG, JPG, GIF, WEBP images to Base64 Data URI format. Instant, offline, supports drag-drop and clipboard paste.
About
Data URIs encode binary image data directly into text using Base64, eliminating external file dependencies. The format follows RFC 2397: data:mediatype;base64,data. Embedding images this way reduces HTTP requests but increases payload size by approximately 33% due to Base64 overhead. Critical consideration: browsers enforce URI length limits - Chrome caps at 2MB for CSS backgrounds, IE8 at 32KB. BMP files lack native browser Data URI support; this tool re-encodes them through Canvas to PNG or JPEG. Incorrect MIME types cause rendering failures. This converter validates magic bytes against declared extensions to prevent silent corruption.
Production use cases: inline CSS backgrounds avoiding CORS, email templates requiring self-contained images, single-file HTML exports, reducing latency for critical above-fold icons. Trade-off analysis required: Base64 defeats gzip compression efficiency and bloats cache size. For images exceeding 10KB, external files with HTTP/2 multiplexing typically outperform Data URIs.
Formulas
Base64 encoding transforms binary octets into ASCII characters from a 64-symbol alphabet. Each group of 3 bytes (24 bits) maps to 4 Base64 characters (6 bits each).
The overhead ratio approaches 43 ≈ 1.33 for large inputs. Including the Data URI prefix adds constant overhead:
where mimeType is the IANA-registered media type (e.g., image/png). Padding characters (=) appear when input length ≠ 0 mod 3.
Reference Data
| Format | MIME Type | Magic Bytes (Hex) | Native Data URI | Transparency | Compression | Typical Use |
|---|---|---|---|---|---|---|
| BMP | image/bmp | 42 4D | Limited | No | None/RLE | Windows legacy |
| PNG | image/png | 89 50 4E 47 | Yes | Yes (Alpha) | Lossless | Icons, screenshots |
| JPEG | image/jpeg | FF D8 FF | Yes | No | Lossy | Photos |
| GIF | image/gif | 47 49 46 38 | Yes | Yes (1-bit) | Lossless (LZW) | Simple animations |
| WebP | image/webp | 52 49 46 46 | Yes | Yes (Alpha) | Both | Web optimization |
| ICO | image/x-icon | 00 00 01 00 | Yes | Yes | None | Favicons |
| SVG | image/svg+xml | 3C 73 76 67 or 3C 3F 78 6D 6C | Yes | Yes | Text (gzip) | Vector graphics |
| AVIF | image/avif | 00 00 00 * 66 74 79 70 | Yes | Yes | Lossy/Lossless | Next-gen photos |
| TIFF | image/tiff | 49 49 2A 00 or 4D 4D 00 2A | No | Yes | Various | Print/archival |
| HEIC | image/heic | 00 00 00 * 66 74 79 70 | No | Yes | Lossy | Apple photos |