2024-05-04 03:39:37 -04:00
|
|
|
from PIL import Image, ImageFile, UnidentifiedImageError
|
2024-04-07 14:27:40 -04: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 02:32:41 -05:00
|
|
|
|
|
|
|
def open_image(path):
|
2024-05-04 03:39:37 -04:00
|
|
|
prev_value = None
|
|
|
|
|
|
|
|
try:
|
2024-05-04 02:32:41 -05:00
|
|
|
img = Image.open(path)
|
2024-05-04 03:39:37 -04:00
|
|
|
except (UnidentifiedImageError, ValueError): #PIL issues #4472 and #2445
|
|
|
|
prev_value = ImageFile.LOAD_TRUNCATED_IMAGES
|
2024-05-04 02:32:41 -05:00
|
|
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
|
|
|
img = Image.open(path)
|
|
|
|
finally:
|
2024-05-04 03:39:37 -04:00
|
|
|
if prev_value is not None:
|
|
|
|
ImageFile.LOAD_TRUNCATED_IMAGES = prev_value
|
2024-05-04 02:32:41 -05:00
|
|
|
return img
|