From 987be17ea16a0c19ff9c990e39d3610bffd7254c Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 31 Dec 2025 17:00:13 +0530 Subject: [PATCH] perf: Reduce memory usage of exif stripping (#35566) This was at least 4x inefficient because of: - Way too many copies of same buffers - Serialization of binary data to python integers :woozy: using `list()` --- frappe/utils/image.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/frappe/utils/image.py b/frappe/utils/image.py index bae933c224..dd70e796ed 100644 --- a/frappe/utils/image.py +++ b/frappe/utils/image.py @@ -37,13 +37,8 @@ def strip_exif_data(content, content_type) -> bytes: if content_type == "image/jpeg" and original_image.mode in ("RGBA", "P"): original_image = original_image.convert("RGB") - new_image = Image.new(original_image.mode, original_image.size) - new_image.putdata(list(original_image.getdata())) - new_image.save(output, format=content_type.split("/")[1]) - - content = output.getvalue() - - return content + original_image.save(output, format=content_type.split("/")[1], exif=b"") + return output.getvalue() def optimize_image(content, content_type, max_width=1024, max_height=768, optimize=True, quality=85):