The Base64 Image Converter BETA Features coming soon
- Reverse Base64
- Optionally optimize the images first (including animated gif/png)
- Instructions for optimal caching and use, which is so essential.
- Upload/Get a css file and automatically convert all the background-images in it to base64
- Support many additional formats, including audio/video/text/etc
- Conversion from one image format to another pre-base64
- Multiple Uploads/Gets, Better Preview Options, Re-sizing
- Image conversion for use in emails (non-remote, so no warning)
Base64 Image Data URL Scheme
Some applications that use URLs also have a need to embed (small) media type data directly inline. This document defines a new URL scheme that would work like 'immediate addressing'. The URLs are of the form:
<mediatype> is an Internet media type specification (with optional parameters.) The appearance of "
;base64" means that the data is encoded as base64. Without "
;base64", the data (as a sequence of octets) is represented using ASCII encoding for octets inside the range of safe URL characters and using the standard
%xx hex encoding of URLs for octets outside that range. If
<mediatype> is omitted, it defaults to
text/plain;charset=US-ASCII. As a shorthand, "
text/plain" can be omitted but the charset parameter supplied.
data:" URL scheme is only useful for short values. Note that some applications that use URLs may impose a length limit; for example, URLs embedded within
<A> anchors in HTML have a length limit determined by the SGML declaration for HTML [RFC1866]. The LITLEN (1024) limits the number of characters which can appear in a single
attribute value literal, the ATTSPLEN (2100) limits the sum of all lengths of all attribute value specifications which appear in a tag, and the TAGLEN (2100) limits the overall length of a tag.
Data URL Scheme Syntax
dataurl := "data:" [ mediatype ] [ ";base64" ] "," data mediatype := [ type "/" subtype ] *( ";" parameter ) data := *urlchar parameter := attribute "=" value
Mobile Web Application Best Practices
Include Background Images Inline in CSS Style Sheets
Visual effects (e.g. background images and gradients) are often used to improve the look and feel of an application. These can be included in CSS as base64 encoded strings in order to avoid an additional HTTP request
Note that base64 encoding adds around 10% to the image size after gzip compression and this additional cost should be weighed against the benefits of fewer requests.
Background images can be encoded using the data URI scheme: url('data:image/png;base64, [data])
[ CSS ] Requires: RFC2397 data uri support.
Data URI scheme
The data URI scheme is a URI scheme (Uniform Resource Identifier scheme) that provides a way to include data in-line in web pages as if they were external resources. This technique allows normally separate elements such as images and style sheets to be fetched in a single HTTP request rather than multiple HTTP requests, which can be more efficient.
Data URIs tends to be simpler than other inclusion methods, such as MIME with cid or mid URIs. Data URIs are sometimes called Uniform Resource Locators, although they do not actually locate anything remote. The data URI scheme is defined in RFC 2397 of the Internet Engineering Task Force (IETF).
The IETF published the data URI specification in 1998 as Proposed Standard on the IETF Standards Track, and hasn't progressed it since. The HTML 4.01 specification refers to the data URI scheme, and data URIs have now been implemented in most browsers.
Web browser support
As of March 2012, Data URIs are supported by the following web browsers:
- Gecko-based, such as Firefox, SeaMonkey, XeroBank, Camino, Fennec and K-Meleon
- Konqueror, via KDE's KIO slaves input/output system
- Opera (including devices such as the Nintendo DSi or Wii)
- WebKit-based, such as Safari (including iOS), Android's browser, Kindle 4's browser, Epiphany and Midori (WebKit is a derivative of Konqueror's KHTML engine, but Mac OS X does not share the KIO architecture so the implementations are different), and Webkit/Chromium-based, such as Chrome
link(data URI must be base64 encoded)
- CSS declarations that accept a URL, such as
- Internet Explorer 9: Internet Explorer 9 does not have 32KB limitation and allowed in broader elements.
- HTTP request and header traffic is not required for embedded data, so data URIs consume less bandwidth whenever the overhead of encoding the inline content as a data URI is smaller than the HTTP overhead. For example, the required base64 encoding for an image 600 bytes long would be 800 bytes, so if an HTTP request required more than 200 bytes of overhead, the data URI would be more efficient.
- For transferring many small files (less than a few kilobytes each), this can be faster. TCP transfers tend to start slowly. If each file requires a new TCP connection, the transfer speed is limited by the round-trip time rather than the available bandwidth. Using HTTP keep-alive improves the situation, but may not entirely alleviate the bottleneck.
- When browsing a secure HTTPS web site, web browsers commonly require that all elements of a web page be downloaded over secure connections, or the user will be notified of reduced security due to a mixture of secure and insecure elements. On badly configured servers, HTTPS requests have significant overhead over common HTTP requests, so embedding data in data URIs may improve speed in this case.
- Web browsers are usually configured to make only a certain number of (often two) concurrent HTTP connections to a domain, so inline data frees up a download connection for other content.
- Environments with limited or restricted access to external resources may embed content when it is disallowed or impractical to reference it externally. For example, an advanced HTML editing field could accept a pasted or inserted image and convert it to a data URI to hide the complexity of external resources from the user. Alternatively, a browser can convert (encode) image based data from the clipboard to a data URI and paste it in a HTML editing field. Mozilla Firefox 4 supports this functionality.
- It is possible to manage a multimedia page as a single file.
- Email message templates can contain images (for backgrounds or signatures) without the image appearing to be an "attachment".
- Data URIs are not separately cached from their containing documents (e.g. CSS or HTML files) so data are downloaded every time the containing documents are redownloaded.
- Content must be re-encoded and re-embedded every time a change is made.
- Internet Explorer through version 7 (approximately 5% of web traffic as of September 2011), lacks support. However this can be overcome by serving browser specific content.
- Internet Explorer 8 limits data URIs to a maximum length of 32 KB. (Internet Explorer 9 does not have this limitation)
- Data are included as a simple stream, and many processing environments (such as web browsers) may not support using containers (such as
message/rfc822) to provide greater complexity such as metadata, data compression, or content negotiation.
- Base64-encoded data URIs are 1/3 larger in size than their binary equivalent. (However, this overhead is reduced to 2-3% if the HTTP server compresses the response using gzip)
- Data URIs do not carry a filename as a normal linked file would. When saving, a default filename for the specified MIME type is generally used.
- Referencing the same resource (such as an embedded small image) more than once from the same document results in multiple copies of the embedded resource. In comparison, an external resource can be referenced arbitrarily many times, yet downloaded and decoded only once.
- Data URIs make it more difficult for security software to filter content.
The encoding is indicated by
;base64. If it's present the data is encoded as base64. Without it the data (as a sequence of octets) is represented using ASCII encoding for octets inside the range of safe URL characters and using the standard %xx hex encoding of URLs for octets outside that range. If
<MIME-type> is omitted, it defaults to
text/plain;charset=US-ASCII. (As a shorthand, the type can be omitted but the charset parameter supplied.)
Some browsers (Chrome, Opera, Safari, Firefox) accept a non-standard ordering if both
;charset are supplied, while Internet Explorer requires that the charset's specification must precede the base64 token.
What tools does Smush.it use to smush images?
We have found many good tools for reducing image size. Often times these tools are specific to particular image formats and work much better in certain circumstances than others. To "smush" really means to try many different image reduction algorithms and figure out which one gives the best result.
These are the algorithms currently in use:
- ImageMagick: to identify the image type and to convert GIF files to PNG files.
- pngcrush: to strip unneeded chunks from PNGs. We are also experimenting with other PNG reduction tools such as pngout, optipng, pngrewrite. Hopefully these tools will provide improved optimization of PNG files.
- jpegtran: to strip all metadata from JPEGs (currently disabled) and try progressive JPEGs.
- gifsicle: to optimize GIF animations by stripping repeating pixels in different frames.
More Info and Resources
The Base 64 Alphabet
Value Encoding Value Encoding Value Encoding Value Encoding 0 A 17 R 34 i 51 z 1 B 18 S 35 j 52 0 2 C 19 T 36 k 53 1 3 D 20 U 37 l 54 2 4 E 21 V 38 m 55 3 5 F 22 W 39 n 56 4 6 G 23 X 40 o 57 5 7 H 24 Y 41 p 58 6 8 I 25 Z 42 q 59 7 9 J 26 a 43 r 60 8 10 K 27 b 44 s 61 9 11 L 28 c 45 t 62 + 12 M 29 d 46 u 63 / 13 N 30 e 47 v 14 O 31 f 48 w (pad) = 15 P 32 g 49 x 16 Q 33 h 50 y
- RFC 1866 - Hypertext Markup Language - 2.0
- RFC 2045 - Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
- RFC 2046 - Definition of media types
- RFC 2077 - Model top-level media type
- RFC 2396 - Uniform Resource Identifiers (URI): Generic Syntax
- RFC 2397 - The "data" URL scheme
- RFC 3023 - Media types based on XML
- RFC 4648 - The Base16, Base32, and Base64 Data Encodings
- RFC 6657 - Update to MIME regarding "charset" Parameter Handling in Textual Media Types
- RFC 5988 - Web Linking
W3 / IANA Docs
- Rules for rendering objects
- Inserting multimedia objects into HTML3
- Rules for handling parsing errors
- Image Media Types
Mozilla Developer Docs
- data URIs
- (*) data: URL tests
- Embedding an image via data: url
- Storing an image from a foreign origin
- Writing efficient CSS
- CSP policy directives: Data URIs
- GIF image; Defined in RFC 2045 and RFC 2046
- JPEG JFIF image; Defined in RFC 2045 and RFC 2046
- JPEG JFIF image; Associated with Internet Explorer; Listed in ms775147(v=vs.85) - Progressive JPEG, initiated before global browser support for progressive JPEGs (Microsoft and Firefox).
- Portable Network Graphics; Registered, Defined in RFC 2083
- SVG vector image; Defined in SVG Tiny 1.2 Specification Appendix M
- Tag Image File Format (only for Baseline TIFF); Defined in RFC 3302
- ICO image; Registered
- Image to data URI convertor
- DataURL.net: Your one-stop HTML5 spot for all things Data URL
- The data: URI kitchen
- php: data://
- Using Data URLs Effectively with Cascading Style Sheets
- getID3: PHP script that extracts useful information from MP3s & other multimedia file formats: