2024-05-04 07:39:37 +00:00
|
|
|
from PIL import Image, ImageFile, UnidentifiedImageError
|
2024-04-07 18:27:40 +00:00
|
|
|
|
|
|
|
def conditioning_set_values(conditioning, values={}):
|
|
|
|
c = []
|
|
|
|
for t in conditioning:
|
|
|
|
n = [t[0], t[1].copy()]
|
|
|
|
for k in values:
|
|
|
|
n[1][k] = values[k]
|
|
|
|
c.append(n)
|
|
|
|
|
|
|
|
return c
|
2024-05-04 07:32:41 +00:00
|
|
|
|
|
|
|
def open_image(path):
|
2024-05-04 07:39:37 +00:00
|
|
|
prev_value = None
|
|
|
|
|
|
|
|
try:
|
2024-05-04 07:32:41 +00:00
|
|
|
img = Image.open(path)
|
2024-05-04 07:39:37 +00:00
|
|
|
except (UnidentifiedImageError, ValueError): #PIL issues #4472 and #2445
|
|
|
|
prev_value = ImageFile.LOAD_TRUNCATED_IMAGES
|
2024-05-04 07:32:41 +00:00
|
|
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
|
|
|
img = Image.open(path)
|
|
|
|
finally:
|
2024-05-04 07:39:37 +00:00
|
|
|
if prev_value is not None:
|
|
|
|
ImageFile.LOAD_TRUNCATED_IMAGES = prev_value
|
2024-05-04 07:32:41 +00:00
|
|
|
return img
|