php save image to html

Recently, there is a need to save pictures and texts in html. The first thing that comes to my mind is mht, which is a format from Microsoft, which can save all styles and pictures in web pages. So I searched the Internet for the method of generating mht, There are two ways to search, one is to save the web page as mht with ie, and the other is to use html2mht software to generate mht

First of all, I wrote an html by hand, which refers to a local image, opened it with ie and saved it as mht, but found that chrome could not be opened, and the generated mht contained a file to reference the image, ie could open it, but chrome could not open it for security reasons. open, method rejected

I used that software to convert another mht, ok, it stuck for a long time, still ie can be opened, but chrome still can’t open, use ie to generate mht again, chrome still can’t open, the method is rejected

I thought that the pictures in mht are saved in the way of data plus some encoding. I searched and found that it is base64, so file_get_contents plus base64_encode reads the file and converts the encoding, pastes the encoding into src, the data type is declared, but the picture It just can't come out. It is displayed after splicing an img tag image with a string. It is found that the generated encoding is different. Why is this?

In order to facilitate copying, I output the code to the textarea, and the copying is also very stuck. Finally, I save it and open it, and the picture is displayed normally. Success!

Need to say, the format of the picture is

<img src="data:image/jpeg;base64,编码内容">

Don't forget the English comma. It is estimated that the picture can be displayed as long as the data:image plus base64 declaration is used. The following picture format declaration should have little visual impact.

In addition, it is very difficult to paste into notepad++, and the window resizing and sliding are not smooth. It is recommended to output tags and coding content directly in php

The entire size of the html encoded by base64 is about 1.33 times the size of the original file. If there are no special requirements, it is not recommended to use base64 images.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325430812&siteId=291194637