chatgpt-vision / utils.py
dipta007's picture
updated pil antialias
34ead5f
raw
history blame
355 Bytes
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