CoolFace
Apppublic

meinvlv/personal_agent_starter

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
image_processing.py26 linesDownload Raw Back to root
1import os2import io3import base644import uuid5from PIL import Image6 7# Helper functions for image processing8def encode_image(image_path: str) -> str:9    """Convert an image file to base64 string."""10    with open(image_path, "rb") as image_file:11        return base64.b64encode(image_file.read()).decode("utf-8")12 13 14def decode_image(base64_string: str) -> Image.Image:15    """Convert a base64 string to a PIL Image."""16    image_data = base64.b64decode(base64_string)17    return Image.open(io.BytesIO(image_data))18 19 20def save_image(image: Image.Image, directory: str = "image_outputs") -> str:21    """Save a PIL Image to disk and return the path."""22    os.makedirs(directory, exist_ok=True)23    image_id = str(uuid.uuid4())24    image_path = os.path.join(directory, f"{image_id}.png")25    image.save(image_path)26    return image_path