"src/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "48b895c989a2f80436a254ff25f5cb634d5d10e7"
Commit 72508a8d authored by comfyanonymous's avatar comfyanonymous
Browse files

Only set LOAD_TRUNCATED_IMAGES when if the Image open fails.

Document which PIL issues this works around.
parent 0d45efb7
from PIL import Image, ImageFile
from PIL import Image, ImageFile, UnidentifiedImageError
def conditioning_set_values(conditioning, values={}):
c = []
......@@ -11,14 +11,15 @@ def conditioning_set_values(conditioning, values={}):
return c
def open_image(path):
try :
ImageFile.LOAD_TRUNCATED_IMAGES = False
img = Image.open(path)
prev_value = None
except:
try:
img = Image.open(path)
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment