webdev_base64_image_encoder
Encode an image as base64, detect its real MIME type and pixel dimensions, and generate ready-to-paste embed snippets for HTML, CSS, JavaScript, and JSON.
Instructions
Base64 Image Encoder With Code Snippets. Decode a base64-encoded image, sniff its real MIME type and pixel dimensions from the file header (PNG, JPEG, GIF, WebP), and emit ready-to-paste embed snippets: raw base64, a data URI, CSS background rules, HTML img/inline-style tags, a JavaScript variable, and a JSON descriptor. Pass the image bytes as base64 in the fileData field (a full data:...;base64,... URI is also accepted and stripped). Use this when you want embeddable code for a raster image; use webdev_data_uri_generator to turn arbitrary text/SVG/MIME content into a data URI without image-dimension detection, or file_base64_file_encoder to base64-encode a non-image file. Runs locally on the data you provide: read-only, non-destructive, contacts no external service, and is rate-limited. Returns detected MIME type, width, height, byte sizes, the base64 string, and a keyed set of code snippets.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fileData | Yes | The image as base64. A bare base64 payload or a full data:<mime>;base64,<...> URI is accepted; the prefix and whitespace are stripped. Must decode to a PNG, JPEG, GIF, or WebP; invalid or non-image data returns HTTP 400. | |
| fileName | No | Base name used in the generated snippets (CSS class, img alt, JS variable). Non-alphanumeric characters become hyphens. Defaults to image. | |
| fileType | No | MIME type to write into the data URI, e.g. image/png. Defaults to the MIME detected from the file header. | |
| includeDataUri | No | Include the full data-URI output entry. Defaults to true. | |
| includeMimeType | No | Retained in the echoed options. Defaults to true. | |
| format | No | Snippet preference echoed back in options. Defaults to inline. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| originalFileName | No | Sanitized base name used in the snippets. | |
| detectedMimeType | No | MIME type sniffed from the file header (image/png, image/jpeg, image/gif, image/webp). | |
| imageWidth | No | Image width in pixels, read from the header. | |
| imageHeight | No | Image height in pixels, read from the header. | |
| originalSize | No | Decoded image size in bytes. | |
| base64Size | No | Length of the base64 string in characters. | |
| base64Data | No | Normalized raw base64 (no data-URI prefix, no whitespace). | |
| outputs | No | Keyed code snippets (base64, dataUri, css, cssComplete, htmlImg, htmlInline, javascript, json); each value has title, description, and content strings. | |
| options | No | Echoed request options: includeDataUri, includeMimeType, format. | |
| error | No | Present instead of the above when input is invalid or not a supported image. |