From 2d887187d207d0b38cd033c8d49a4babc388f6a5 Mon Sep 17 00:00:00 2001 From: MitulDavid Date: Fri, 6 Aug 2021 18:31:41 +0530 Subject: [PATCH] refactor: Toggle optimization using checkbox --- frappe/public/icons/timeless/symbol-defs.svg | 3 --- .../js/frappe/file_uploader/FilePreview.vue | 15 +++++++++------ frappe/utils/image.py | 7 +++++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/frappe/public/icons/timeless/symbol-defs.svg b/frappe/public/icons/timeless/symbol-defs.svg index 555ea6ee7e..6108daa938 100644 --- a/frappe/public/icons/timeless/symbol-defs.svg +++ b/frappe/public/icons/timeless/symbol-defs.svg @@ -702,7 +702,4 @@ - - - diff --git a/frappe/public/js/frappe/file_uploader/FilePreview.vue b/frappe/public/js/frappe/file_uploader/FilePreview.vue index 9e2fafb1e9..73adeb6fbb 100644 --- a/frappe/public/js/frappe/file_uploader/FilePreview.vue +++ b/frappe/public/js/frappe/file_uploader/FilePreview.vue @@ -20,9 +20,6 @@ - @@ -31,6 +28,7 @@ {{ file.file_obj.size | file_size }} +
diff --git a/frappe/utils/image.py b/frappe/utils/image.py index 556c5e4a32..88d885e442 100644 --- a/frappe/utils/image.py +++ b/frappe/utils/image.py @@ -40,6 +40,9 @@ def strip_exif_data(content, content_type): return content def optimize_image(content, content_type, max_width=1920, max_height=1080, optimize=True, quality=85): + if content_type == 'image/svg+xml': + return content + image = Image.open(io.BytesIO(content)) image_format = content_type.split('/')[1] size = max_width, max_height @@ -48,5 +51,5 @@ def optimize_image(content, content_type, max_width=1920, max_height=1080, optim output = io.BytesIO() image.save(output, format=image_format, optimize=optimize, quality=quality, save_all=True if image_format=='gif' else None) - content = output.getvalue() - return content \ No newline at end of file + optimized_content = output.getvalue() + return optimized_content if len(optimized_content) < len(content) else content \ No newline at end of file