mirror of
https://github.com/vladmandic/automatic
synced 2026-09-04 12:00:46 +02:00
make image metadata optional
This commit is contained in:
+2
-1
@@ -329,7 +329,8 @@
|
||||
{"id":"","label":"Path to directory with LyCORIS network(s)","localized":"","hint":""},
|
||||
{"id":"","label":"Path to user-defined styles file","localized":"","hint":""},
|
||||
{"id":"","label":"Always save all generated images","localized":"","hint":""},
|
||||
{"id":"","label":"File format for generated images","localized":"","hint":""},
|
||||
{"id":"","label":"File format for generated images","localized":"","hint":"Select file format for images"},
|
||||
{"id":"","label":"Include metadata in saved images","localized":"","hint":"Save image create parameters as metadata tags inside image file"},
|
||||
{"id":"","label":"Images filename pattern","localized":"","hint":"Use following tags to define how filenames for images are chosen: [steps], [cfg], [prompt_hash], [prompt], [prompt_no_styles], [prompt_spaces], [width], [height], [styles], [sampler], [seed], [model_hash], [model_name], [prompt_words], [date], [datetime], [datetime<Format>], [datetime<Format><Time Zone>], [job_timestamp]; leave empty for default"},
|
||||
{"id":"","label":"Add number to filename when saving","localized":"","hint":""},
|
||||
{"id":"","label":"Always save all generated image grids","localized":"","hint":""},
|
||||
|
||||
+4
-3
@@ -441,23 +441,24 @@ def atomically_save_image():
|
||||
image_format = 'JPEG'
|
||||
shared.log.debug(f'Saving image: {image_format} {fn} {image.size}')
|
||||
# actual save
|
||||
exifinfo_data = (exifinfo_data or "") if shared.opts.image_metadata else ""
|
||||
if image_format == 'PNG':
|
||||
pnginfo_data = PngImagePlugin.PngInfo()
|
||||
for k, v in params.pnginfo.items():
|
||||
pnginfo_data.add_text(k, str(v))
|
||||
image.save(fn, format=image_format, quality=shared.opts.jpeg_quality, pnginfo=pnginfo_data)
|
||||
image.save(fn, format=image_format, quality=shared.opts.jpeg_quality, pnginfo=pnginfo_data if shared.opts.image_metadata else None)
|
||||
elif image_format == 'JPEG':
|
||||
if image.mode == 'RGBA':
|
||||
shared.log.warning('Saving RGBA image as JPEG: Alpha channel will be lost')
|
||||
image = image.convert("RGB")
|
||||
elif image.mode == 'I;16':
|
||||
image = image.point(lambda p: p * 0.0038910505836576).convert("L")
|
||||
exif_bytes = piexif.dump({ "Exif": { piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(exifinfo_data or "", encoding="unicode") } })
|
||||
exif_bytes = piexif.dump({ "Exif": { piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(exifinfo_data, encoding="unicode") } })
|
||||
image.save(fn, format=image_format, quality=shared.opts.jpeg_quality, exif=exif_bytes)
|
||||
elif image_format == 'WEBP':
|
||||
if image.mode == 'I;16':
|
||||
image = image.point(lambda p: p * 0.0038910505836576).convert("RGB")
|
||||
exif_bytes = piexif.dump({ "Exif": { piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(exifinfo_data or "", encoding="unicode") } })
|
||||
exif_bytes = piexif.dump({ "Exif": { piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(exifinfo_data, encoding="unicode") } })
|
||||
try:
|
||||
image.save(fn, format=image_format, quality=shared.opts.jpeg_quality, lossless=shared.opts.webp_lossless, exif=exif_bytes)
|
||||
except Exception as e:
|
||||
|
||||
@@ -359,6 +359,7 @@ options_templates.update(options_section(('system-paths', "System Paths"), {
|
||||
options_templates.update(options_section(('saving-images', "Image Options"), {
|
||||
"samples_save": OptionInfo(True, "Always save all generated images"),
|
||||
"samples_format": OptionInfo('jpg', 'File format for generated images', gr.Dropdown, lambda: {"choices": ["jpg", "png", "webp", "tiff", "jp2"]}),
|
||||
"image_metadata": OptionInfo(True, "Include metadata in saved images"),
|
||||
"samples_filename_pattern": OptionInfo("[seed]-[prompt_spaces]", "Images filename pattern", component_args=hide_dirs),
|
||||
"save_images_add_number": OptionInfo(True, "Add number to filename when saving", component_args=hide_dirs),
|
||||
"grid_save": OptionInfo(True, "Always save all generated image grids"),
|
||||
|
||||
Reference in New Issue
Block a user