Convert image to base64

Converts an image to base64 for embedding HTML into a page or CSS.
Reduce final image: The picture will be scaled down proportionally

Convert an image to base64 (data image base64) sometimes it is necessary to reduce the number of HTTP requests to server. This is a good way to display icons on a website. In this case, the body of the image can be placed in a HTML page code or in a CSS file, where instead of SRC or URL you substitute the code base64.

But you should understand that the base64 code weighs about 33% more than the file itself, so it is not recommended to display large images in this way.

But if base64 is used for icons or small pictures, then in some cases, in addition to reducing requests to the server, you can also gain in the final weight of the page. Because the server, in addition to the image itself, also sends HTTP headers, which also have weight and are added to the weight of the image. And for an icon it may turn out that the sum of its weight and headings will be greater than the weight of base64.

Base64 is a standard for encoding binary data using 64 ASCII characters. The coding alphabet contains text-numeric Latin characters A-Z, a-z and 0-9 (62 characters) and 2 additional characters, depending on the implementation system. Every 3 source bytes are encoded with 4 characters, resulting in a 33% increase in data.