Automaticism/Promptvision

Avoid non-image files.

ChrisYangTW opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
When there are non-picture files in the folder, it will raise <PIL.UnidentifiedImageError>.
Screenshot 2023-03-26 at 21 52 44

Describe the solution you'd like
The filter_images_in_image_folder_path() function on line 64 of the gallery.py code seems to be unable to avoid non-picture files, so that an exception is thrown.

Additional context
This project is very useful. The built-in image viewing program is somewhat inefficient, and I hope your project can continue to be optimized.

This should be avoided since the filtered images are only added if they are image files. And as you see it’s a png. But I can add a try catch for this issue to handle broken image files

This should be avoided since the filtered images are only added if they are image files. And as you see it’s a png. But I can add a try catch for this issue to handle broken image files

Hi. Thanks for your reply.
I forgot to mention earlier that I use Mac OS, and this type of file(dot underscore ._ files) will only appear on that system.
The is_valid_image_extension() function on line 890 of the gallery.py code just judge the suffix of the file.
Since this kind of file is not a image file, PIL will throw an exception after reading it.

Personally, I patched this code here to avoid the problem. If possible, maybe you can improve it a little in the next update, although there are very few people who use Mac to play stable diffusion.😭😭😭

line 890 of gallery.py:

def is_valid_image_extension(filename): 
    ...
    if sys.platform == 'darwin' and filename.startswith('._'):
        return False
    return filename.endswith(".jpg") or filename.endswith(".jpeg") or filename.endswith(".png")

Perhaps it seems more straightforward to use try statement to avoid broken files as you said.