add support for reading saved jpeg comments
This commit is contained in:
parent
eeabe62b4d
commit
b6b9faa779
2 changed files with 24 additions and 8 deletions
|
@ -6,6 +6,8 @@ from modules.shared import opts
|
||||||
import modules.gfpgan_model
|
import modules.gfpgan_model
|
||||||
from modules.ui import plaintext_to_html
|
from modules.ui import plaintext_to_html
|
||||||
import modules.codeformer_model
|
import modules.codeformer_model
|
||||||
|
import piexif
|
||||||
|
|
||||||
|
|
||||||
cached_images = {}
|
cached_images = {}
|
||||||
|
|
||||||
|
@ -73,8 +75,20 @@ def run_extras(image, gfpgan_visibility, codeformer_visibility, codeformer_weigh
|
||||||
|
|
||||||
|
|
||||||
def run_pnginfo(image):
|
def run_pnginfo(image):
|
||||||
|
items = image.info
|
||||||
|
|
||||||
|
if "exif" in image.info:
|
||||||
|
exif = piexif.load(image.info["exif"])
|
||||||
|
exif_comment = (exif or {}).get("Exif", {}).get(piexif.ExifIFD.UserComment, b'')
|
||||||
|
exif_comment = exif_comment.decode("utf8", 'ignore')
|
||||||
|
items['exif comment'] = exif_comment
|
||||||
|
|
||||||
|
for field in ['jfif', 'jfif_version', 'jfif_unit', 'jfif_density', 'dpi', 'exif']:
|
||||||
|
del items[field]
|
||||||
|
|
||||||
|
|
||||||
info = ''
|
info = ''
|
||||||
for key, text in image.info.items():
|
for key, text in items.items():
|
||||||
info += f"""
|
info += f"""
|
||||||
<div>
|
<div>
|
||||||
<p><b>{plaintext_to_html(str(key))}</b></p>
|
<p><b>{plaintext_to_html(str(key))}</b></p>
|
||||||
|
|
|
@ -325,14 +325,16 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
|
||||||
if not os.path.exists(fullfn):
|
if not os.path.exists(fullfn):
|
||||||
break
|
break
|
||||||
|
|
||||||
if extension == "png":
|
if extension.lower() in ("jpg", "jpeg"):
|
||||||
image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo)
|
exif_bytes = piexif.dump({
|
||||||
|
"Exif": {
|
||||||
|
piexif.ExifIFD.UserComment: info.encode("utf8"),
|
||||||
|
}
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
exif_dict = { "Exif" : dict() }
|
exif_bytes = None
|
||||||
exif_dict["Exif"][piexif.ExifIFD.UserComment] = piexif.helper.UserComment.dump(
|
|
||||||
info, encoding="unicode")
|
image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo, exif=exif_bytes)
|
||||||
exif_bytes = piexif.dump(exif_dict)
|
|
||||||
image.save(fullfn, quality=opts.jpeg_quality, exif=exif_bytes)
|
|
||||||
|
|
||||||
target_side_length = 4000
|
target_side_length = 4000
|
||||||
oversize = image.width > target_side_length or image.height > target_side_length
|
oversize = image.width > target_side_length or image.height > target_side_length
|
||||||
|
|
Loading…
Reference in a new issue