Data:image/png; what is Base64

time:17-07-04 forum:HTML web page, JS language and code
  http://www.cnblogs.com/XL-Liang/archive... 30509.html

you may notice that there are some pictures of SRC or background pictures behind a large string of characters, such as: Code]data:image/png; Base64, iVBORw0KGgoAAAANSUhEUgAAAAEAAAAkCAYAAABIdFAMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHhJREFUeNo8zjsOxCAMBFB/ KEAUFFR0Cbng3nQPw68ArZdAlOZppPFIBhH5EAB8b Tlt9MYQ6i1BuqFaq1CKSVcxZ2Acs6406KUgpt5/ LCKuVgz5BDCSb13ZO99ZOdcZGvt4mJjzMVKqcha68iIePB86GAiOv8CDADlIUQ Bs7MD3wAAAABJRU5ErkJggg==. So what is this? This is Data URI scheme. [/code]
Data URI scheme is defined in RFC2397 with the aim of embedding some small data directly into a web page so that it does not need to be loaded from an external file. For example, the string of characters, in fact, is a small picture that copies the characters to the Firefox's address bar and goes to it, and you can see it, a 1X36's gray PNG picture. In
, in the Data URI above, data represents the name of the protocol for the data, image/png is the name of the data type, the base64 is the encoding method of the data, and the comma is the data after the base64 encoded by the image/png file.

currently, the types of Data URI scheme are:
[code]data:, text data
data:text/plain, text data
data:text/html, HTML code. Ta:text/javascript, Javascript code
data:text/javascript; Base64, Base64 coded Javascript code
data:image/gif; Base64, Base64 encoded GIF picture data. Base64, Base64 encoded icon picture data
[/code]

Base64, in simple terms, it translates some 8-bit data into standard ASCII characters, and there are many free Base64 encoding and decoding tools on the Internet, and in PHP, a function base64_encode () can be encoded. ("wg.png");
currently, IE8, Firfox, Chrome and Opera browsers support this kind of small file embedding.


an example of a picture:
a picture in a web page that can be displayed in this way:

[code].lt; img src= "http://www.letuknowit.com/images/wg.png" /.gt. AEAAAAkCAYAAABIdFAMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHhJREFUeNo8zjsOxCAMBF
B/KEAUFFR0Cbng3nQPw68ArZdAlOZppPFIBhH5EAB8b Tlt9MYQ6i1BuqFaq1CKSVcxZ2Acs6406KUgpt5/LCKuVgz5BDCSb13ZO99ZOdcZGvt4mJjzMVKqcha68iIePB86GAiOv8CDADlIUQBs7MD
3wAAAABJRU5ErkJggg== '/.gt; [/code]

we wrote the contents of the image file directly in the HTML file. The advantage of this is that we save a HTTP request. The disadvantage is that browsers do not cache this image. We can make free choice according to the actual situation

prev:Ji'nan has made decisive efforts to tack... next:Dandelion fluttering in the lower left c...
post comment
Notice



approved   May 1 go to these scenic spots to pl...   Do not work to go to school and not ...   Tea table "dark words"   Bazhong man built a small wooden bri...   The army flags the banner of the fla...
rand   Breaking the restriction of the phot...   Open a new window with the window.op...   HTML page automatic loading method   Web small game realized by JavaScrip...   HTML commonly used escape characters
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com