Tiktok-Talent-Info/utils/image_processing.py

13 lines
289 B
Python
Raw Normal View History

2025-01-23 21:50:55 +08:00
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()