File size: 327 Bytes
68cf8d3 2c5de2c 68cf8d3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import base64
from PIL import Image
import io
def convert_image_to_base64(file) -> str:
with Image.open(file.path) as img:
buffer = io.BytesIO()
img = img.convert('RGB')
img.save(buffer, format="JPEG")
image_data = base64.b64encode(buffer.getvalue()).decode("utf-8")
return image_data
|