From cc2c3e18eee25c40c5638b4397d9d7339a500294 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Tue, 9 Jan 2024 02:04:37 +0100 Subject: [PATCH] upgraded utility --- lollms/utilities.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lollms/utilities.py b/lollms/utilities.py index 8041bce..ee29442 100644 --- a/lollms/utilities.py +++ b/lollms/utilities.py @@ -98,15 +98,19 @@ def encode_image(image_path, max_image_width=-1): image = Image.open(image_path) width, height = image.size + # Check and convert image format if needed + if image.format not in ['PNG', 'JPEG', 'GIF', 'WEBP']: + image = image.convert('JPEG') + + if max_image_width != -1 and width > max_image_width: ratio = max_image_width / width new_width = max_image_width new_height = int(height * ratio) + f = image.format image = image.resize((new_width, new_height)) + image.format = f - # Check and convert image format if needed - if image.format not in ['PNG', 'JPEG', 'GIF', 'WEBP']: - image = image.convert('JPEG') # Save the image to a BytesIO object byte_arr = io.BytesIO()