The url value of the src or css background image is the base64 encoded code

The url value of the src or css background image is the base64 encoded code
You may have noticed that the src or CSS background image URLs of some images on the web are followed by a long string of characters, such as: data:image/png;base64, iVBORw0KGgoAAAANSUhEUgnZVJlYWR5ccllPAAAAHhJREFUeNo8zjsOxCAMBFB/KEAUFFR0Cbng3nQPw68ArZdAlOZppPFIBhH5EAB8b+Tlt9MYQ6i1BuqFaq1CKSVcxZ2Acs6406KUgpt5/KuVgz5BDCSZO99ZOdcZGvt4mJjzMVKqcha68iIePB86GAiOv8CDADlIUQBs7MD3wAAAABJRU5ErkJggg%3D%3D. So what is this? This is the Data URI scheme.

The Data URI scheme is defined in RFC2397. Its purpose is to embed some small data directly into a web page without having to load it from an external file. For example, the string of characters above is actually a small picture. Copy and paste these characters into the address bar of Firefox and go to it, then you can see it, a 1X36 white and gray png picture.

In the above Data URI, data represents the protocol name for obtaining data, image/png is the data type name, base64 is the data encoding method, and the data after the comma is the base64-encoded data of the image/png file.

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 image data
data:image/x-icon;base64, base64-encoded icon image data

Simply put, base64 translates some 8-bit data into standard ASCII characters. There are many free base64 encoding and decoding tools on the Internet. In PHP, you can use the base64_encode() function to encode, such as echo base64_encode(file_get_contents('wg.png'));
Currently, IE8, Firfox, Chrome, and Opera browsers all support this type of small file embedding.

Take an example of a picture:

A picture on a web page can be displayed like this:
<img src="upload/2022/web/wg.png"/>
It can also be displayed like this:

Copy code
The code is as follows:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAkCAYAAABIdFAMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHhJREFUeNo8zjsOxCAMBFB/KEAUFFR0Cbng3nQPw68ArZdAlOZppPFIBhH5EAB8b+Tlt9MYQ6i1BuqFaq1CKSVcxZ2Acs6406KUgpt5/LCKuVgz5BDCSb13ZO99ZOdcZGvt4mJjzMVKqcha68iIePB86GAiOv8CDADlIUQBs7MD3wAAAABJRU5ErkJggg%3D%3D"/>

We write the content of the image file directly into the HTML file. The advantage of this is that it saves an HTTP request. The downside is that the browser will not cache such images. You can make free choices based on the actual situation.

<<:  How to modify Flash SWF files in web pages

>>:  MySQL statement to get all dates or months in a specified time period (without setting stored procedures or adding tables)

Recommend

Detailed explanation of MySQL master-slave inconsistency and solutions

1. MySQL master-slave asynchrony 1.1 Network Dela...

MySQL trigger detailed explanation and simple example

MySQL trigger simple example grammar CREATE TRIGG...

Windows10 mysql 8.0.12 non-installation version configuration startup method

This article shares the specific steps for config...

HTML table tag tutorial (44): table header tag

<br />In order to clearly distinguish the ta...

Vue+flask realizes video synthesis function (drag and drop upload)

Table of contents We have written about drag and ...

MySQL-8.0.26 Configuration Graphics Tutorial

Preface: Recently, the company project changed th...

Detailed explanation of Linux environment variable configuration strategy

When customizing the installation of software, yo...

Several ways to generate unique IDs in JavaScript

Possible solutions 1. Math.random generates rando...

MySQL uses find_in_set() function to implement where in() order sorting

This article introduces a tutorial about how to u...

Implementation of JavaScript downloading linked images and uploading them

Since we are going to upload pictures, the first ...

Using jQuery to implement the carousel effect

What I bring to you today is to use jQuery to imp...

How to set up cross-domain access in IIS web.config

Requirement: The page needs to display an image, ...

Notes on the MySQL database backup process

Today I looked at some things related to data bac...

Does MySql need to commit?

Whether MySQL needs to commit when performing ope...