mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Gracefully handles corrupted images; fixes #1486
- App does not crash if corrupted image loaded - Error is displayed in the UI console and CLI output if an image cannot be loaded
This commit is contained in:
parent
b908f2b4bc
commit
9d34213b4c
@ -334,11 +334,10 @@ class InvokeAIWebServer:
|
|||||||
image_array = []
|
image_array = []
|
||||||
|
|
||||||
for path in image_paths:
|
for path in image_paths:
|
||||||
|
try:
|
||||||
if os.path.splitext(path)[1] == ".png":
|
if os.path.splitext(path)[1] == ".png":
|
||||||
metadata = retrieve_metadata(path)
|
metadata = retrieve_metadata(path)
|
||||||
# sd_metadata = metadata["sd-metadata"]
|
|
||||||
else:
|
else:
|
||||||
# sd_metadata = {}
|
|
||||||
metadata = {}
|
metadata = {}
|
||||||
|
|
||||||
pil_image = Image.open(path)
|
pil_image = Image.open(path)
|
||||||
@ -351,15 +350,18 @@ class InvokeAIWebServer:
|
|||||||
image_array.append(
|
image_array.append(
|
||||||
{
|
{
|
||||||
"url": self.get_url_from_image_path(path),
|
"url": self.get_url_from_image_path(path),
|
||||||
"thumbnail": self.get_url_from_image_path(thumbnail_path),
|
"thumbnail": self.get_url_from_image_path(
|
||||||
|
thumbnail_path
|
||||||
|
),
|
||||||
"mtime": os.path.getmtime(path),
|
"mtime": os.path.getmtime(path),
|
||||||
"metadata": metadata,
|
"metadata": metadata,
|
||||||
# "metadata": sd_metadata,
|
|
||||||
"width": width,
|
"width": width,
|
||||||
"height": height,
|
"height": height,
|
||||||
"category": category,
|
"category": category,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
socketio.emit("error", {"message": f"Unable to load {path}"})
|
||||||
|
|
||||||
socketio.emit(
|
socketio.emit(
|
||||||
"galleryImages",
|
"galleryImages",
|
||||||
@ -402,11 +404,10 @@ class InvokeAIWebServer:
|
|||||||
|
|
||||||
image_array = []
|
image_array = []
|
||||||
for path in image_paths:
|
for path in image_paths:
|
||||||
|
try:
|
||||||
if os.path.splitext(path)[1] == ".png":
|
if os.path.splitext(path)[1] == ".png":
|
||||||
metadata = retrieve_metadata(path)
|
metadata = retrieve_metadata(path)
|
||||||
# sd_metadata = metadata["sd-metadata"]
|
|
||||||
else:
|
else:
|
||||||
# sd_metadata = {}
|
|
||||||
metadata = {}
|
metadata = {}
|
||||||
|
|
||||||
pil_image = Image.open(path)
|
pil_image = Image.open(path)
|
||||||
@ -419,15 +420,19 @@ class InvokeAIWebServer:
|
|||||||
image_array.append(
|
image_array.append(
|
||||||
{
|
{
|
||||||
"url": self.get_url_from_image_path(path),
|
"url": self.get_url_from_image_path(path),
|
||||||
"thumbnail": self.get_url_from_image_path(thumbnail_path),
|
"thumbnail": self.get_url_from_image_path(
|
||||||
|
thumbnail_path
|
||||||
|
),
|
||||||
"mtime": os.path.getmtime(path),
|
"mtime": os.path.getmtime(path),
|
||||||
# "metadata": sd_metadata,
|
|
||||||
"metadata": metadata,
|
"metadata": metadata,
|
||||||
"width": width,
|
"width": width,
|
||||||
"height": height,
|
"height": height,
|
||||||
"category": category,
|
"category": category,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
print(f'>> Unable to load {path}')
|
||||||
|
socketio.emit("error", {"message": f"Unable to load {path}"})
|
||||||
|
|
||||||
socketio.emit(
|
socketio.emit(
|
||||||
"galleryImages",
|
"galleryImages",
|
||||||
|
Loading…
Reference in New Issue
Block a user