diff options
author | JJ <jjisnow@gmail.com> | 2022-09-12 11:40:02 +0000 |
---|---|---|
committer | AUTOMATIC1111 <16777216c@gmail.com> | 2022-09-13 15:11:46 +0000 |
commit | 34cf684419f5d7774244ec555944a95678dd4756 (patch) | |
tree | b18c8894a84b44aa2f1f6b9cf190d7a4d5cf7be5 /modules/images.py | |
parent | 55e08dd61f7f64324e9a2ed3b466d270e94e1382 (diff) | |
download | stable-diffusion-webui-gfx803-34cf684419f5d7774244ec555944a95678dd4756.tar.gz stable-diffusion-webui-gfx803-34cf684419f5d7774244ec555944a95678dd4756.tar.bz2 stable-diffusion-webui-gfx803-34cf684419f5d7774244ec555944a95678dd4756.zip |
add metadata to jpg and non-png image files
* needs a piexif module install
* dumps the info in an Exif "UserComment"
* update to webui.bat
Diffstat (limited to 'modules/images.py')
-rw-r--r-- | modules/images.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/modules/images.py b/modules/images.py index fc9a0113..27d558ed 100644 --- a/modules/images.py +++ b/modules/images.py @@ -5,6 +5,8 @@ from collections import namedtuple import re
import numpy as np
+import piexif
+import piexif.helper
from PIL import Image, ImageFont, ImageDraw, PngImagePlugin
from fonts.ttf import Roboto
import string
@@ -323,7 +325,14 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i if not os.path.exists(fullfn):
break
- image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo)
+ if extension == "png":
+ image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo)
+ else:
+ exif_dict = { "Exif" : dict() }
+ exif_dict["Exif"][piexif.ExifIFD.UserComment] = piexif.helper.UserComment.dump(
+ info, encoding="unicode")
+ exif_bytes = piexif.dump(exif_dict)
+ image.save(fullfn, quality=opts.jpeg_quality, exif=exif_bytes)
target_side_length = 4000
oversize = image.width > target_side_length or image.height > target_side_length
@@ -335,7 +344,7 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i elif oversize:
image = image.resize((image.width * target_side_length // image.height, target_side_length), LANCZOS)
- image.save(f"{fullfn_without_extension}.jpg", quality=opts.jpeg_quality, pnginfo=pnginfo)
+ image.save(fullfn, quality=opts.jpeg_quality, exif=exif_bytes)
if opts.save_txt and info is not None:
with open(f"{fullfn_without_extension}.txt", "w", encoding="utf8") as file:
|