Tiktok-Talent-Info/utils/image_processing.py
2025-01-23 21:50:55 +08:00

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()