Spaces:
Running
Running
from PIL import Image | |
from io import BytesIO | |
import base64 | |
# Convert Image to Base64 | |
def im_2_b64(image): | |
image = Image.open(image) | |
image.thumbnail((512, 512), Image.Resampling.LANCZOS) | |
image = image.convert("RGB") | |
buff = BytesIO() | |
image.save(buff, format="JPEG") | |
img_str = base64.b64encode(buff.getvalue()) | |
return img_str | |