From a8f1fd9689120f7359c3d60681a554bb8d93edbd Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Mon, 12 Jan 2026 20:09:02 -0700 Subject: [PATCH 1/2] Skip images that Pillow can't process --- RELEASE.md | 3 +++ pelican/plugins/image_process/image_process.py | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 RELEASE.md diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000..3ed01b4 --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,3 @@ +Release type: patch + +- Skip images that Pillow can't process, and let Pelican look for them at their original, unprocessed locations diff --git a/pelican/plugins/image_process/image_process.py b/pelican/plugins/image_process/image_process.py index 644fc5e..f436721 100644 --- a/pelican/plugins/image_process/image_process.py +++ b/pelican/plugins/image_process/image_process.py @@ -448,13 +448,21 @@ def process_img_tag(img, settings, derivative): path = compute_paths(img["src"], settings, derivative) process = settings["IMAGE_PROCESS"][derivative] - img["src"] = posixpath.join(path.base_url, path.filename) destination = os.path.join(str(path.base_path), path.filename) if not isinstance(process, list): process = process["ops"] - image_size = process_image((path.source, destination, process), settings) + try: + image_size = process_image((path.source, destination, process), settings) + except (UnidentifiedImageError, FileNotFoundError): + image_size = None + else: + # Only try and find the image at the new location (in the generated + # site) if we've processed the image successfully. Otherwise, default + # to the original location + img["src"] = posixpath.join(path.base_url, path.filename) + if image_size: if "width" not in img.attrs: img["width"] = image_size[0] @@ -749,8 +757,9 @@ def process_image(image, settings): try: i = try_open_image(image[0]) - except (UnidentifiedImageError, FileNotFoundError): - return None + except (UnidentifiedImageError, FileNotFoundError): # noqa: TRY203 + # return None + raise for step in image[2]: if callable(step): From 38529afc571ec06965b298d1ea1b532205df380d Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Mon, 12 Jan 2026 20:50:33 -0700 Subject: [PATCH 2/2] Log skipped pictures at the INFO level --- pelican/plugins/image_process/image_process.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pelican/plugins/image_process/image_process.py b/pelican/plugins/image_process/image_process.py index f436721..f094074 100644 --- a/pelican/plugins/image_process/image_process.py +++ b/pelican/plugins/image_process/image_process.py @@ -721,9 +721,7 @@ def try_open_image(path): try: i = Image.open(path) except UnidentifiedImageError: - logger.warning( - f'{LOG_PREFIX} Source image "{path}" is not supported by Pillow.' - ) + logger.info(f'{LOG_PREFIX} Source image "{path}" is not supported by Pillow.') raise except FileNotFoundError: logger.warning(f'{LOG_PREFIX} Source image "{path}" not found.')