From 53644ce773d1fac79fa1e1ab6f59ff0df51dae49 Mon Sep 17 00:00:00 2001 From: David Vogt Date: Thu, 21 Nov 2024 12:26:06 +0100 Subject: [PATCH] fix performance in convert engine: exif orientation In other calls to the ImageMagick commandline tools, the suffix "[0]" is added so it only looks at the first page if it's a multi-page document such as a PDF. For some reason, this is missing in the `_get_exif_orientation()` method, and may cause very long runtimes when dealing with large documents (several hundred pages of PDF). --- sorl/thumbnail/engines/convert_engine.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sorl/thumbnail/engines/convert_engine.py b/sorl/thumbnail/engines/convert_engine.py index 320148885..2a9dbe6b4 100644 --- a/sorl/thumbnail/engines/convert_engine.py +++ b/sorl/thumbnail/engines/convert_engine.py @@ -110,7 +110,8 @@ def is_valid_image(self, raw_data): def _get_exif_orientation(self, image): args = settings.THUMBNAIL_IDENTIFY.split() - args.extend(['-format', '%[exif:orientation]', image['source']]) + image_param = f"{image['source']}[0]" + args.extend(["-format", "%[exif:orientation]", image_param]) p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.wait() result = p.stdout.read().strip()