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 data URI scheme supports the following types: data:, Text data 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 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 image data DATA:IMAGE/JPEG;BASE64,BASE64 encoded JPEG picture data DATA:IMAGE/X-ICON;BASE64,BASE64 encoded icon image data base64 simply said, It translates some 8-bit data into standard ASCII characters, and there are many free base64 encoding and decoding tools on the Web, which can be encoded in PHP using function Base64_encode (), such asEcho 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 as follows:
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.
Data:image/png;base64