JS display Base64 encoded binary streaming Web page picture _javascript tips

Source: Internet
Author: User
Tags base64

Data URI Scheme.
Data URI scheme is defined in RFC2397 to embed some small data directly into a Web page so that no longer has to be loaded from an external file. For example, the above string of characters, in fact, is a small picture, these characters will be copied sticky paste into the address bar of Firefox and go to, you can see it, a 2*2 of white gif pictures.
in the data URI above, data represents the contract name for the acquisition, Image/gif is the data type name, base64 is the encoding method of the data, followed by the Image/gif file Base64 encoded data.
Currently, the types supported by data URI scheme are:
Data:, Text data
Data:text/plain, text data
data:text/html,html code
Data:text/html;b ASE64,BASE64 encoded HTML code
DATA:TEXT/CSS,CSS code
DATA:TEXT/CSS;BASE64,BASE64 encoded CSS code
Data:text/javascript, JavaScript code
DATA:TEXT/JAVASCRIPT;BASE64,BASE64 encoded JavaScript code
DATA:IMAGE/GIF;BASE64,BASE64 encoded GIF image data
DATA:IMAGE/PNG;BASE64,BASE64 encoded PNG picture data
DATA:IMAGE/JPEG;BASE64,BASE64 encoded JPEG image data
Data:image/x-icon; BASE64,BASE64 encoded icon image data
Base64 simply, it translates some 8-bit data into standard ASCII characters, and there are many free base64 encoding and decoding tools available in PHP, which can be used with function Base64_encode ( ) for encoding, such as Echo Base64_encode (file_get_contents (' images/log.gif '));
Currently, IE8, Firfox, Chrome, opera browsers support this small file embedding.
Example of a picture:
A picture in a Web page can be displayed like this:

Copy Code code as follows:



You can also display this:
Copy Code code as follows:



The benefit of this is that we have written the contents of the image file directly in the HTML file, saving an HTTP request. The downside is that browsers do not cache this image.

PS: Here again to provide you with an online image base64 coding tool and Base64 Code conversion tool for everyone to reference the use of:

picture conversion to Base64 encoding online tool : http://tools.jb51.net/transcoding/img2base64

BASE64 encoding and decoding tool:http://tools.jb51.net/transcoding/base64

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.