From 77ce5a49e48a07b06e8200ab9bcc4bda9f463b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bournhonesque?= Date: Wed, 25 Dec 2024 15:57:04 +0100 Subject: [PATCH] fix: convert image to RGB after cropping if needed --- robotoff/app/api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/robotoff/app/api.py b/robotoff/app/api.py index a486c449e6..998a6c5ce4 100644 --- a/robotoff/app/api.py +++ b/robotoff/app/api.py @@ -949,6 +949,9 @@ def on_get(self, req: falcon.Request, resp: falcon.Response): def image_response(image: Image.Image, resp: falcon.Response) -> None: resp.content_type = "image/jpeg" fp = io.BytesIO() + # JPEG doesn't support RGBA, so we convert to RGB if needed + if image.mode != "RGB": + image = image.convert("RGB") image.save(fp, "JPEG") stream_len = fp.tell() fp.seek(0)