Introduction to using data URI scheme to embed images in web pages

Introduction to using data URI scheme to embed images in web pages
The data URI scheme allows us to include data in a web page using inline code, which can be used in Html, CSS, Javascript, etc.

The data URI scheme is often used to embed images into web pages, as follows:
<img alt="He Chongtian's headshot (your browser does not support the data URI scheme, the image cannot be displayed)" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBcQFxAAD/2wBD/*A lot of data is omitted here*/NONPmfvcqcdZR7XT27n//2Q%3D%3D"/>

The data URI scheme has the following format:
data:[<MIME-type>][;base64],<data>

This format is relatively simple. By comparison, we can see that the above img is a jpg image encoded using base64.
Embed this img into this page and it will be displayed as follows:
He Chongtian's headshot (your browser does not support the data URI scheme, the image cannot be displayed
In addition to base64 encoding, you can also use hexadecimal URL encoding in the form of %xx, as follows:
: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :

Generate image data According to the above format, we can write a small program to generate it, but we don’t need to be so troublesome. There are many websites that provide this (free) service.

Here are a few:

1. http://dataurl.sveinbjorn.org/dataurlmaker

Provide preview and easy copying.

2. http://websemantics.co.uk/online_tools/image_to_data_uri_convertor/

Provides preview and can generate corresponding CSS URI data.

3. http://software.hixie.ch/utilities/cgi/data/data

Tip: The generation is not limited to image data. There are three ways to use it (see 1, 2, 3 in the figure below). You can specify the encoding method, but the interface is not friendly.

Use in group presentations

Click the Insert/Edit Image button:

The following window pops up. Use any of the above URLs to generate image data and copy and paste it into the image address text box:

Click Insert, OK, as shown below:

View the effect: http://space.cnblogs.com/group/topic/41938/

<<:  Solution to the problem that the border style of the <td></td> tag cannot be displayed in the browser

>>:  Complete list of CentOS7 firewall operation commands

Recommend

Install Zookeeper under Docker (standalone and cluster)

After starting Docker, let's take a look at t...

Mysql example of splitting into multiple rows and columns by specific symbols

Some fault code tables use the following design p...

Example of how to exit the loop in Array.forEach in js

Table of contents forEach() Method How to jump ou...

Docker deploys Laravel application to realize queue & task scheduling

In the previous article, we wrote about how to de...

How to use MyCat to implement MySQL master-slave read-write separation in Linux

Table of contents Linux-Use MyCat to implement My...

How to use nginx as a proxy cache

The purpose of using cache is to reduce the press...

Detailed explanation of the usage of image tags in HTML

In HTML, the <img> tag is used to define an...

Detailed explanation of Docker daemon security configuration items

Table of contents 1. Test environment 1.1 Install...

Implementation of Docker deployment of web projects

The previous article has installed the docker ser...

Detailed explanation of how to monitor MySQL statements

Quick Reading Why do we need to monitor SQL state...

JS Asynchronous Stack Tracing: Why await is better than Promise

Overview The fundamental difference between async...

Detailed description of mysql replace into usage

The replace statement is generally similar to ins...

Summary of Node.js service Docker container application practice

This article will not explain the use and install...

Introduction to cloud native technology kubernetes (K8S)

Table of contents 01 What is Kubernetes? 02 The d...