Embed a picture in a page using the Data URL Base64 encoding __ code

Source: Internet
Author: User
Tags base64

Before the company has a demand, backstage hope that the front end as much as possible to reduce the request, I took into account the sprite and other pictures into the Base64 embedded into the page, but finally because the company intranet can not fully access the Internet, after all, shelved. I ran into it today and recorded it.

The idea is to translate the images needed in the page into Base64 encoding, and then embed the code in the CSS picture reference location, or into the SRC in the img tag.

The specific production methods are:

1, open the following Web site

2, according to the instructions of the page, upload the page, and then copy the code after the transcoding, and then add the URL data, or SRC data.

There are a few simple introductions on the site page.

Http://tool.css-js.com/base64.html

I use the background image here to test the way, in fact, is to copy the data after the encoding, put in the background-image:url position. The specific methods are as follows:

div.triangle{
            width:900px;
            height:500px;

            Background-image:url ("Data:image/png;base64,......}"
The test results are as follows:

I feel good.


PS: Several days after the supplement:

How to obtain the Base64 data information of the picture under the condition of network restriction.

Directly above:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.