Base64 image size
Base64 uses 64 different characters, and that is 2 ^ 6. Thus, base64 stores 6 bits per 8-bit character. Thus, the proportion is 6/8 of the raw data to the base64 data. This is not an accurate calculation, but a rough estimate.
Example:
An image size of 48 KB requires about 64 KB as an image with base64 conversion.
Calculation: (48/6) * 8 = 64
A simple CLI calculator for Linux systems:
$ cat /dev/urandom|head -c 48000|base64|wc -c 64843
Or using the image:
$ cat my.png|base64|wc -c
base64 images and websites
This question is much more difficult to answer. Generally speaking, the larger the image, the less meaning base64 uses. But consider the following points:
- Many embedded images in an HTML file or CSS file may have similar lines. For PNG, you will often find duplicate "A" characters. Using gzip (sometimes called "deflate"), there may even be a size gain. But it depends on the content of the image.
- Request HTTP1.1 overhead: especially with lots of cookies, you can easily get a few kilobytes of overhead on request. Attaching base64 images can save bandwidth.
- Do not encode base64 SVG images because gzip is more efficient in XML than in base64.
- Programming. On dynamically generated images, it is easier to deliver them on a single request to coordinate two dependent requests.
- Deeplinks: If you want to prevent the image from loading, itβs a little harder to extract the image from the HTML page.
So the answer is: it depends.
Trendfischer Jul 18 '17 at 16:47 2017-07-18 16:47
source share