From e27805adec76f4092ca86d0268db59a6457811e0 Mon Sep 17 00:00:00 2001 From: freakypie <1542720+freakypie@users.noreply.github.com> Date: Fri, 21 Mar 2025 11:06:09 -0600 Subject: [PATCH 1/2] Update pil_engine.py checking for image_info remove icc_profile if it fails to generate an image get raw_data even if there was an initial exception --- sorl/thumbnail/engines/pil_engine.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sorl/thumbnail/engines/pil_engine.py b/sorl/thumbnail/engines/pil_engine.py index e0921988c..8822df485 100644 --- a/sorl/thumbnail/engines/pil_engine.py +++ b/sorl/thumbnail/engines/pil_engine.py @@ -267,7 +267,7 @@ def _get_raw_data(self, image, format_, quality, image_info=None, progressive=Fa } # keeps icc_profile - if 'icc_profile' in image_info: + if image_info and 'icc_profile' in image_info: params['icc_profile'] = image_info['icc_profile'] raw_data = None @@ -278,11 +278,13 @@ def _get_raw_data(self, image, format_, quality, image_info=None, progressive=Fa # Do not save unnecessary exif data for smaller thumbnail size params.pop('exif', {}) image.save(bf, **params) + raw_data = bf.getvalue() except OSError: - # Try without optimization. + # Try without optimization and icc_profile. params.pop('optimize') + if 'icc_profile' in params: + params.pop('icc_profile') image.save(bf, **params) - else: raw_data = bf.getvalue() finally: bf.close() From 13785b94767eedae915630b45fb12b8ba8785579 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Mar 2025 17:08:07 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorl/thumbnail/engines/pil_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorl/thumbnail/engines/pil_engine.py b/sorl/thumbnail/engines/pil_engine.py index 8822df485..b4a9a7ca7 100644 --- a/sorl/thumbnail/engines/pil_engine.py +++ b/sorl/thumbnail/engines/pil_engine.py @@ -282,7 +282,7 @@ def _get_raw_data(self, image, format_, quality, image_info=None, progressive=Fa except OSError: # Try without optimization and icc_profile. params.pop('optimize') - if 'icc_profile' in params: + if 'icc_profile' in params: params.pop('icc_profile') image.save(bf, **params) raw_data = bf.getvalue()