Image to Base64 Converter Online Tool




About Image to Base64 Converter Online Tool:

This online Image to Base64 Converter tool helps you to convert image into base64 string, to help you embed images within html.

cartoon image to base64

Use Base64 to embed Image in HTML:

Embed Image in HTML can reduce the http connection when a user load a webpage, because the information of the image is within the HTML code. It's good for icon and other small image, but not a good idea to use embed image when the image size is over 2Mb. The use case:

<img src="data:image/png;base64,ivborw0kggoaaaansuheugaaaama..." width="300" height="100" alt="base64 image"/>

Use Base64 as background Image in CSS:

Another use case for Base64 Image is in CSS:

.body {
    background: url('data:image/png;base64,ivborw0kggoaaaansuheugaaaama...');
}

Images Cache Policy:

All uploaded Images will be deleted after 1 hour, so please download the result as soon as possible. DO NOT use this server as your image hosting service.

Convert Image to Base64 with Python (with package Base64):

from PIL import Image  # pip3 install pillow
import base64

origin_file_path = './origin.jpeg'
image_type = str(Image.open(origin_file_path).format).lower()

with open(origin_file_path, "rb") as image_file:
    encoded_string = base64.b64encode(image_file.read())

base64_string = "data:image/" + image_type + ";base64," + encoded_string.decode()