webdev_data_uri_generator
Generate a data URI from text or base64 file to embed inline in HTML, CSS, or JavaScript without separate file fetches. Returns encoding variations and a recommended option.
Instructions
Data URI Generator From Text Or Base64 File. Build a data: URI from supplied content so it can be embedded inline in HTML, CSS, or JavaScript with no separate file fetch. Two modes via inputMethod: text base64- and URL-encodes a raw string (textInput) and returns both variants plus the shorter recommended one; file wraps an already-base64-encoded payload (fileData) and sniffs/optimizes its MIME type. Use this for arbitrary text, SVG markup, CSS, JS, or any MIME you name; use webdev_base64_image_encoder instead when you have a raster image and need pixel-dimension detection, or encoding_decoding_base64 for plain base64 encode/decode without the data: wrapper. Runs locally on the data you provide: read-only, non-destructive, contacts no external service, idempotent, and rate-limited (30 requests/minute for anonymous callers). Returns the data URI(s), MIME type, byte sizes, encoding variations, a recommended encoding, suitability analysis, and optional embed code examples.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputMethod | No | Which source to encode. text uses textInput; file uses fileData. Defaults to file. | file |
| textInput | No | Raw text/markup to encode (text mode). Required and non-empty when inputMethod is text; empty returns HTTP 400. | |
| mimeType | No | MIME type written into the text-mode data URI, e.g. text/plain, text/html, text/css, image/svg+xml. Defaults to text/plain. | text/plain |
| encoding | No | Charset label used when includeCharset is true (text mode). Defaults to utf-8. | utf-8 |
| fileData | No | File bytes as base64 (file mode). A bare base64 payload or a full data:<mime>;base64,<...> URI is accepted; the prefix is stripped. Required and non-empty when inputMethod is file; empty or invalid base64 returns HTTP 400. | |
| fileName | No | File name used for extension-based MIME detection and in generated examples (file mode). Defaults to file. | file |
| fileType | No | Provided MIME type for the file (file mode); may be overridden by detected type. Defaults to application/octet-stream. | application/octet-stream |
| includeCharset | No | When true (text mode), also emit charset-tagged base64 and URL-encoded variations. Defaults to false. | |
| optimizeSize | No | Echoed back in options; size is always compared across variations. Defaults to false. | |
| generateExamples | No | Include ready-to-paste embed code examples in the response. Defaults to true. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputMethod | No | Echoes which mode produced the result: text or file. | |
| textInput | No | Echo of the input string (text mode only). | |
| mimeType | No | MIME type used in the data URI (text mode; also nested in analysis). | |
| encoding | No | Charset label used (text mode). | |
| textLength | No | UTF-8 byte length of the input text (text mode). | |
| variations | No | Text mode: data URIs keyed by encoding - base64, urlencoded, and (when includeCharset) base64_charset, urlencoded_charset. | |
| recommended | No | The shortest variation data URI (text mode). | |
| originalFileName | No | Echo of fileName (file mode). | |
| providedMimeType | No | The fileType supplied by the caller (file mode). | |
| detectedMimeType | No | MIME type sniffed from content/extension, or null if undetermined (file mode). | |
| originalSize | No | Decoded payload size in bytes (file mode). | |
| dataUriSize | No | Character length of the generated data URI (file mode). | |
| sizeOverhead | No | Percentage size increase of the data URI over the raw bytes (file mode). | |
| dataUri | No | The generated base64 data URI (file mode). | |
| optimizedDataUri | No | Data URI rebuilt with the detected MIME type when it differs (file mode). | |
| isOptimized | No | True when optimizedDataUri differs from dataUri (file mode). | |
| analysis | No | Breakdown of the data URI: mimeType, isBase64Encoded, hasCharset, parameters, isImage, isText, suitableFor (file mode), or inputLength, variationCount, mostEfficient, savings, recommendations (text mode). | |
| examples | No | Keyed embed snippets (HTML img, CSS background, iframe, link, script, JavaScript, JSON, download anchor) when generateExamples is true. |