Please wait...

Convert Image(PIL) in Base64

by in Python
import base64
from io import BytesIO
from PIL import Image

def get_base64(image):
    buffered = BytesIO()
    image.save(buffered, format="JPEG")
    img_str = base64.b64encode(buffered.getvalue())
    return "data:image/jpeg;base64," + img_str.decode()

im = Image.open("sample.jpg")
base_image = get_base64(im)