node_helpers.py 699 Bytes
Newer Older
1
from PIL import ImageFile, UnidentifiedImageError
2
3
4
5
6
7
8
9
10
11

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
12

13
def pillow(fn, arg):
14
15
    prev_value = None
    try:
16
17
        x = fn(arg)
    except (OSError, UnidentifiedImageError, ValueError): #PIL issues #4472 and #2445, also fixes ComfyUI issue #3416
18
        prev_value = ImageFile.LOAD_TRUNCATED_IMAGES
19
        ImageFile.LOAD_TRUNCATED_IMAGES = True
20
        x = fn(arg)
21
    finally:
22
23
        if prev_value is not None:
            ImageFile.LOAD_TRUNCATED_IMAGES = prev_value
24
        return x