File size: 426 Bytes
19b3da3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import io
from PIL import Image
def to_bytes(image: Image.Image) -> bytes:
with io.BytesIO() as output:
image.save(output, format="JPEG")
return output.getvalue()
def resize_image_to512(image: Image.Image) -> Image.Image:
iw, ih = image.size
if iw > ih:
image = image.resize((512, int(512 * ih / iw)))
else:
image = image.resize((int(512 * iw / ih), 512))
return image
|