From 0abff499e2e40fb308b406b82ad3f850683720e3 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 22 Mar 2023 16:03:05 -0300 Subject: [PATCH] Use image.thumbnail --- extensions/sd_api_pictures/script.py | 10 +--------- extensions/send_pictures/script.py | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/extensions/sd_api_pictures/script.py b/extensions/sd_api_pictures/script.py index 1f6ba2d2..cc85f3b3 100644 --- a/extensions/sd_api_pictures/script.py +++ b/extensions/sd_api_pictures/script.py @@ -89,15 +89,7 @@ def get_SD_pictures(description): image.save(output_file.as_posix()) pic_id += 1 # lower the resolution of received images for the chat, otherwise the log size gets out of control quickly with all the base64 values in visible history - width, height = image.size - if (width > 300): - height = int(height * (300 / width)) - width = 300 - elif (height > 300): - width = int(width * (300 / height)) - height = 300 - newsize = (width, height) - image = image.resize(newsize, Image.LANCZOS) + image.thumbnail((300, 300)) buffered = io.BytesIO() image.save(buffered, format="JPEG") buffered.seek(0) diff --git a/extensions/send_pictures/script.py b/extensions/send_pictures/script.py index 46393e6c..196c7d53 100644 --- a/extensions/send_pictures/script.py +++ b/extensions/send_pictures/script.py @@ -26,15 +26,7 @@ def caption_image(raw_image): def generate_chat_picture(picture, name1, name2): text = f'*{name1} sends {name2} a picture that contains the following: "{caption_image(picture)}"*' # lower the resolution of sent images for the chat, otherwise the log size gets out of control quickly with all the base64 values in visible history - width, height = picture.size - if (width > 300): - height = int(height * (300 / width)) - width = 300 - elif (height > 300): - width = int(width * (300 / height)) - height = 300 - newsize = (width, height) - picture = picture.resize(newsize, Image.LANCZOS) + image.thumbnail((300, 300)) buffer = BytesIO() picture.save(buffer, format="JPEG") img_str = base64.b64encode(buffer.getvalue()).decode('utf-8')