Update node_helpers.py to include open_image helper function

open_image includes try except to catch Pillow Value Errors that occur when large ICC profiles are embedded in images.
This commit is contained in:
shawnington 2024-04-27 09:54:56 -06:00 committed by GitHub
parent fd763c9afd
commit e8f0d40b6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,4 @@
from PIL import Image, ImageFile
def conditioning_set_values(conditioning, values={}): def conditioning_set_values(conditioning, values={}):
c = [] c = []
@ -8,3 +9,16 @@ def conditioning_set_values(conditioning, values={}):
c.append(n) c.append(n)
return c return c
def open_image(path):
try :
ImageFile.LOAD_TRUNCATED_IMAGES = False
img = Image.open(path)
except:
ImageFile.LOAD_TRUNCATED_IMAGES = True
img = Image.open(path)
finally:
ImageFile.LOAD_TRUNCATED_IMAGES = False
return img