From bbcc4ba6fb02b158646250b02a00f236210edbb9 Mon Sep 17 00:00:00 2001 From: pangbo13 <373108669@qq.com> Date: Thu, 30 Mar 2023 09:54:54 +0800 Subject: [PATCH] ignore images PIL cannot handle --- scripts/image_browser.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/image_browser.py b/scripts/image_browser.py index 0c9d7b2..03ace66 100644 --- a/scripts/image_browser.py +++ b/scripts/image_browser.py @@ -747,15 +747,19 @@ def get_all_images(dir_name, sort_by, sort_order, keyword, tab_base_tag_box, img def get_image_thumbnail(image_list): thumbnail_list = [] for image_path in image_list: - image = Image.open(image_path) - width, height = image.size - left = (width - min(width, height)) / 2 - top = (height - min(width, height)) / 2 - right = (width + min(width, height)) / 2 - bottom = (height + min(width, height)) / 2 - image = image.crop((left, top, right, bottom)) - image.thumbnail((opts.image_browser_thumbnail_size, opts.image_browser_thumbnail_size)) - thumbnail_list.append(image) + try: + image = Image.open(image_path) + width, height = image.size + left = (width - min(width, height)) / 2 + top = (height - min(width, height)) / 2 + right = (width + min(width, height)) / 2 + bottom = (height + min(width, height)) / 2 + thumbnail = image.crop((left, top, right, bottom)) + thumbnail.thumbnail((opts.image_browser_thumbnail_size, opts.image_browser_thumbnail_size)) + except OSError: + thumbnail_list.append(image_path) + else: + thumbnail_list.append(thumbnail) return thumbnail_list def get_image_page(img_path, page_index, filenames, keyword, sort_by, sort_order, tab_base_tag_box, img_path_depth, ranking_filter, aes_filter_min, aes_filter_max, exif_keyword, negative_prompt_search, use_regex, case_sensitive):