Base64 is a type of 8bit byte code commonly used on the Internet. Base64 can be used to pass longer identification information in the HTTP environment. At the same time, it can Encryption function.
Why transform the picture into base64 encoding?Converting the picture with the Base64 code can reduce the HTTP request, because the picture can be passed directly to the client in the form of character coding, and the file form requires HTTP requests. However, there will also be a small disadvantage, that is, the size will become larger when the picture encodes Base64, but it will be almost the same after optimization through GZIP. Therefore, a smaller picture in the process of application can be directly encoded into base64, and large pictures are not recommended to use it.
How does HTML5 convert the picture with Base64?If HTML5 wants to convert the picture with Base64, you need to use a html5 interface Filereader.readasDataurl () interface description. This interface can be converted to the Base64 encoding format, and then it is displayed in the form of data: URL.
Sample programThe following code is an example program, create a new HTML file, and then open the code copy and paste to use the browser supporting HTML5 to open to view the effect.
Copy code