From f745f78cb3293227595c2fd21b7cb84f6f742ecb Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Sun, 11 Dec 2022 13:48:47 -0500 Subject: [PATCH] correct bug when trying to enhance JPG images (#1928) This fix was authored by @mebelz and is reissued here to base it on `main`. --- ldm/invoke/pngwriter.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ldm/invoke/pngwriter.py b/ldm/invoke/pngwriter.py index 3a43b9bc92..c022c62870 100644 --- a/ldm/invoke/pngwriter.py +++ b/ldm/invoke/pngwriter.py @@ -57,8 +57,13 @@ def retrieve_metadata(img_path): metadata stored there, as a dict ''' im = Image.open(img_path) - md = im.text.get('sd-metadata', '{}') - dream_prompt = im.text.get('Dream', '') + if hasattr(im, 'text'): + md = im.text.get('sd-metadata', '{}') + dream_prompt = im.text.get('Dream', '') + else: + # When trying to retrieve metadata from images without a 'text' payload, such as JPG images. + md = '{}' + dream_prompt = '' return {'sd-metadata': json.loads(md), 'Dream': dream_prompt} def write_metadata(img_path:str, meta:dict):