From dd42083d6a6fb179964438ed3fe880e2b6158708 Mon Sep 17 00:00:00 2001 From: Jakub Zenon Kujawa Date: Fri, 22 Nov 2024 09:12:24 +0100 Subject: [PATCH] fix(ocr): convert images to RGB format before processing --- src/ocr/ocr.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ocr/ocr.py b/src/ocr/ocr.py index 73234b1..20056eb 100644 --- a/src/ocr/ocr.py +++ b/src/ocr/ocr.py @@ -96,6 +96,9 @@ def convert_to_base64(images: list[Image.Image]) -> list[str]: encoded_images = [] for img in images: + if img.mode in ("RGBA", "P"): + img = img.convert("RGB") + with io.BytesIO() as buffer: img.save(buffer, format="JPEG") img_byte_arr = buffer.getvalue()