Skip to content

Commit f745f78

Browse files
authored
correct bug when trying to enhance JPG images (#1928)
This fix was authored by @mebelz and is reissued here to base it on `main`.
1 parent 7efe0f3 commit f745f78

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ldm/invoke/pngwriter.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ def retrieve_metadata(img_path):
5757
metadata stored there, as a dict
5858
'''
5959
im = Image.open(img_path)
60-
md = im.text.get('sd-metadata', '{}')
61-
dream_prompt = im.text.get('Dream', '')
60+
if hasattr(im, 'text'):
61+
md = im.text.get('sd-metadata', '{}')
62+
dream_prompt = im.text.get('Dream', '')
63+
else:
64+
# When trying to retrieve metadata from images without a 'text' payload, such as JPG images.
65+
md = '{}'
66+
dream_prompt = ''
6267
return {'sd-metadata': json.loads(md), 'Dream': dream_prompt}
6368

6469
def write_metadata(img_path:str, meta:dict):

0 commit comments

Comments
 (0)