Skip to content

Commit

Permalink
Only set LOAD_TRUNCATED_IMAGES when if the Image open fails.
Browse files Browse the repository at this point in the history
Document which PIL issues this works around.
  • Loading branch information
comfyanonymous committed May 4, 2024
1 parent 0d45efb commit 72508a8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions node_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PIL import Image, ImageFile
from PIL import Image, ImageFile, UnidentifiedImageError

def conditioning_set_values(conditioning, values={}):
c = []
Expand All @@ -11,14 +11,15 @@ def conditioning_set_values(conditioning, values={}):
return c

def open_image(path):
try :
ImageFile.LOAD_TRUNCATED_IMAGES = False
prev_value = None

try:
img = Image.open(path)

except:
except (UnidentifiedImageError, ValueError): #PIL issues #4472 and #2445
prev_value = ImageFile.LOAD_TRUNCATED_IMAGES
ImageFile.LOAD_TRUNCATED_IMAGES = True
img = Image.open(path)

finally:
ImageFile.LOAD_TRUNCATED_IMAGES = False
if prev_value is not None:
ImageFile.LOAD_TRUNCATED_IMAGES = prev_value
return img

0 comments on commit 72508a8

Please sign in to comment.