Merge pull request #10395 from wk5ovc/patch-4

Fix extra networks save preview image geninfo
This commit is contained in:
AUTOMATIC1111 2023-05-17 20:42:37 +03:00 committed by GitHub
commit 9c91a86720
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -344,9 +344,19 @@ def setup_ui(ui, gallery):
assert is_allowed, f'writing to {filename} is not allowed' assert is_allowed, f'writing to {filename} is not allowed'
if geninfo: if geninfo:
ext = os.path.splitext(filename)[1].lower()
if ext == '.png':
pnginfo_data = PngImagePlugin.PngInfo() pnginfo_data = PngImagePlugin.PngInfo()
pnginfo_data.add_text('parameters', geninfo) pnginfo_data.add_text('parameters', geninfo)
image.save(filename, pnginfo=pnginfo_data) image.save(filename, pnginfo=pnginfo_data)
elif ext in ('.jpg', '.jpeg', '.webp'):
exif_bytes = piexif.dump({
'Exif': {piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(geninfo or '',
encoding='unicode')}
})
image.save(filename, exif=exif_bytes, quality=shared.opts.jpeg_quality)
else:
image.save(filename)
else: else:
image.save(filename) image.save(filename)