13 lines
289 B
Python
13 lines
289 B
Python
import io
|
|
import base64
|
|
from PIL import Image
|
|
|
|
def encode_image_base64(image: Image.Image) -> str:
|
|
"""
|
|
Encode a PIL Image to a Base64 string.
|
|
"""
|
|
buffered = io.BytesIO()
|
|
image.save(buffered, format="JPEG")
|
|
return base64.b64encode(buffered.getvalue()).decode()
|
|
|