@@ -405,13 +405,6 @@ def compute_paths(img, settings, derivative):
405405
406406def process_img_tag (img , settings , derivative ):
407407 path = compute_paths (img , settings , derivative )
408- if not is_img_identifiable (path .source ):
409- logger .warning (
410- "%s Skipping image %s that could not be identified by Pillow" ,
411- LOG_PREFIX ,
412- path .source ,
413- )
414- return
415408 process = settings ["IMAGE_PROCESS" ][derivative ]
416409
417410 img ["src" ] = posixpath .join (path .base_url , path .filename )
@@ -423,23 +416,8 @@ def process_img_tag(img, settings, derivative):
423416 process_image ((path .source , destination , process ), settings )
424417
425418
426- def is_img_identifiable (img_filepath ):
427- try :
428- Image .open (img_filepath )
429- return True # noqa: TRY300
430- except (FileNotFoundError , UnidentifiedImageError ):
431- return False
432-
433-
434419def build_srcset (img , settings , derivative ):
435420 path = compute_paths (img , settings , derivative )
436- if not is_img_identifiable (path .source ):
437- logger .warning (
438- "%s Skipping image %s that could not be identified by Pillow" ,
439- LOG_PREFIX ,
440- path .source ,
441- )
442- return
443421 process = settings ["IMAGE_PROCESS" ][derivative ]
444422
445423 default = process ["default" ]
@@ -685,17 +663,28 @@ def process_picture(soup, img, group, settings, derivative):
685663 img .insert_before (s ["element" ])
686664
687665
666+ def try_open_image (path ):
667+ try :
668+ i = Image .open (path )
669+ except UnidentifiedImageError :
670+ logger .warning (
671+ f'{ LOG_PREFIX } Source image "{ path } " is not supported by Pillow.'
672+ )
673+ raise
674+ except FileNotFoundError :
675+ logger .warning (f'{ LOG_PREFIX } Source image "{ path } " not found.' )
676+ raise
677+
678+ return i
679+
680+
688681def process_image (image , settings ):
689682 # remove URL encoding to get to physical filenames
690683 image = list (image )
691684 image [0 ] = unquote (image [0 ])
692685 image [1 ] = unquote (image [1 ])
693686 # image[2] is the transformation
694687
695- logger .debug (f"{ LOG_PREFIX } { image [0 ]} -> { image [1 ]} " )
696-
697- os .makedirs (os .path .dirname (image [1 ]), exist_ok = True )
698-
699688 # If original image is older than existing derivative, skip
700689 # processing to save time, unless user explicitly forced
701690 # image generation.
@@ -704,7 +693,12 @@ def process_image(image, settings):
704693 or not os .path .exists (image [1 ])
705694 or os .path .getmtime (image [0 ]) > os .path .getmtime (image [1 ])
706695 ):
707- i = Image .open (image [0 ])
696+ logger .debug (f"{ LOG_PREFIX } Processing { image [0 ]} -> { image [1 ]} " )
697+
698+ try :
699+ i = try_open_image (image [0 ])
700+ except (UnidentifiedImageError , FileNotFoundError ):
701+ return
708702
709703 for step in image [2 ]:
710704 if callable (step ):
@@ -713,12 +707,16 @@ def process_image(image, settings):
713707 elems = step .split (" " )
714708 i = basic_ops [elems [0 ]](i , * (elems [1 :]))
715709
710+ os .makedirs (os .path .dirname (image [1 ]), exist_ok = True )
711+
716712 # `save_all=True` will allow saving multi-page (aka animated) GIF's
717713 # however, turning it on seems to break PNG support, and doesn't seem
718714 # to work on GIF's either...
719715 i .save (image [1 ], progressive = True )
720716
721717 ExifTool .copy_tags (image [0 ], image [1 ])
718+ else :
719+ logger .debug (f"{ LOG_PREFIX } Skipping { image [0 ]} -> { image [1 ]} " )
722720
723721
724722def dump_config (pelican ):
0 commit comments