stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Bug]: "Batch img2img" read invalid image file (For example like ".DS_Store” on Mac)

Open autumnmotor opened this issue 3 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

on "Batch img2img", img2img.py read invalid file in inputdir(like a ".DS_Store")

Steps to reproduce the problem

Store image files in inputdir (behind the scenes Mac automatically generates ".DS_Store" in same directory)

Run "run_webui_mac.sh"

On Browser(http://127.0.0.1:7860/), run "Batch img2img"

What should have happened?

Batch img2img process is abort.

Commit where the problem happens

No response

What platforms do you use to access UI ?

MacOS

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

No response

Additional information, context and logs

I'm posting here because I don't quite understand how it behaves on github.

I'm using stable-diffusion-webui on my M1Mac. I mainly use "Batch img2img", On Mac, a hidden file called ".DS_Store" is automatically created in each folder (there is no way to turn this off). At that time, in img2img.py

img = Image.open(image)

I read ".DS_Store" and get an error " invalid image file". I may run rm ./.DS_Store periodically, but I import the regex library in img2img.py and

import re

The error is avoided by replacing the work of listing the image files in the folder like this.

images = [file for file in [os.path.join(input_dir, x) for x in os.listdir(input_dir)] if os.path.isfile(file)

images = [file for file in [os.path.join(input_dir, x) for x in os.listdir(input_dir)] if os.path.isfile(file) and not re.search(".DS_Store", file) ]

A more general approach would be to list the valid image files aggressively like this (my regex may not be accurate...).

images = [file for file in [os.path.join(input_dir, x) for x in os.listdir(input_dir)] if os.path.isfile(file) and re.search(".(jpg|png|bmp|...)$", file) ]

Translated by Google. thank you for reading my poor english

autumnmotor avatar Oct 20 '22 23:10 autumnmotor

I don't have a Mac. But I think this shoudn't be a problem, because 图片

leohu1 avatar Jan 07 '23 15:01 leohu1