As you may notice, the URL of a src or CSS background image on a webpage is followed by a large string of characters, such as:
data:image/png;base64,ivborw0kggoaaaansuheugaaaakaaaajaqmaaadax5rtaaaaa3ncsvqicajb4u/gaaaablbmvex///+ zmzmoueqyaaaaanrstlma/1uriruaaaajcehzcwaacusaaarraykldvoaaaawdevydenyzwf0aw9uifrpbwuamdkvmjavmtigkkg+ aaaahhrfwhrtb2z0d2fyzqbbzg9izsbgaxjld29ya3mgq1m26lyyjaaaab1jrefucjljonja8libozybwy6bqqzmatlakymnaf1fbs/ Zpvcnaaaaaelftksuqmcc
So what is this? This is the data URI scheme. The
data URI scheme is defined in RFC2397 to embed some small data directly into a Web page, eliminating the need to load it from an external file. For example, the above string of characters, is actually a small picture, the characters copied and pasted into the address bar of Firefox and go to, you can see it, a 1x36 lime png image.
in the data URI above, data represents the contract name to get the data, Image/png is the data type name, base64 is the data encoding method, and the comma is followed by the Image/png file Base64 encoded data.
Currently, the types supported by the Data URI scheme are:Data
:, Text
data:text/plain, Text data
data:text/html,html Code
data:text/html;base64,base64 encoded HTML code
DATA:TEXT/CSS,CSS Code
data:text/css;base64,base64 coded 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 image 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 on the Web that can be encoded in PHP with function Base64_encode (), such as Echo base64_ Encode (file_get_contents (' wg.png '));
Currently, IE8, Firfox, Chrome, and opera browsers support this small file embedding.
An example of a picture:
a picture in a webpage can be displayed like this:
You can also display this:
The
advantage of having the contents of the image file written directly in the HTML file is that it saves an HTTP request. The downside is that the browser does not cache this image.
1. Study the carousel in bootstrap example