From 9f6dc6cd04ada87b366bd85bd53bdff4d8d0f7ad Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Sat, 18 Mar 2023 20:00:46 +0100 Subject: [PATCH] no point creating two images --- changedetectionio/model/Watch.py | 11 ++++++++--- changedetectionio/store.py | 5 ----- changedetectionio/tests/test_notification.py | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index d25837e9..45ff3f52 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -312,11 +312,16 @@ class model(dict): return None def get_screenshot_as_jpeg(self): - # Created by save_screenshot() - fname = os.path.join(self.watch_data_dir, "last-screenshot.jpg") + fname = os.path.join(self.watch_data_dir, "last-screenshot.png") if os.path.isfile(fname): - return fname + import io + # Make a JPEG that's used in notifications (due to being a smaller size) available + from PIL import Image + im = Image.open(fname) + img_byte_arr = io.BytesIO() + im.save(img_byte_arr, format='JPEG', quality=int(os.getenv("NOTIFICATION_SCREENSHOT_JPG_QUALITY", 75))) + return img_byte_arr.getvalue() # False is not an option for AppRise, must be type None return None diff --git a/changedetectionio/store.py b/changedetectionio/store.py index ad16de93..50802aec 100644 --- a/changedetectionio/store.py +++ b/changedetectionio/store.py @@ -360,11 +360,6 @@ class ChangeDetectionStore: f.write(screenshot) f.close() - # Make a JPEG that's used in notifications (due to being a smaller size) available - from PIL import Image - im1 = Image.open(target_path) - im1.convert('RGB').save(target_path.replace('.png','.jpg'), quality=int(os.getenv("NOTIFICATION_SCREENSHOT_JPG_QUALITY", 75))) - def save_error_text(self, watch_uuid, contents): if not self.data['watching'].get(watch_uuid): diff --git a/changedetectionio/tests/test_notification.py b/changedetectionio/tests/test_notification.py index 8eedcd7c..cce3e877 100644 --- a/changedetectionio/tests/test_notification.py +++ b/changedetectionio/tests/test_notification.py @@ -81,8 +81,9 @@ def test_check_notification(client, live_server): datastore = 'test-datastore' with open(os.path.join(datastore, str(uuid), 'last-screenshot.png'), 'wb') as f: f.write(base64.b64decode(testimage_png)) - with open(os.path.join(datastore, str(uuid), 'last-screenshot.jpg'), 'wb') as f: - f.write(base64.b64decode(testimage_jpg)) +# We no longer create two images +# with open(os.path.join(datastore, str(uuid), 'last-screenshot.jpg'), 'wb') as f: +# f.write(base64.b64decode(testimage_jpg)) # Goto the edit page, add our ignore text # Add our URL to the import page