1
0
Fork 0

dump json parameters to str before writing to exif

This commit is contained in:
Sean Sube 2023-06-26 07:14:32 -05:00
parent 91c6c62159
commit f142f83ad5
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 44 additions and 14 deletions

View File

@ -7,7 +7,7 @@ from PIL import Image
from ..chain import blend_mask, upscale_outpaint from ..chain import blend_mask, upscale_outpaint
from ..chain.utils import process_tile_order from ..chain.utils import process_tile_order
from ..output import save_image, save_params from ..output import save_image
from ..params import ( from ..params import (
Border, Border,
HighresParams, HighresParams,
@ -314,7 +314,9 @@ def run_txt2img_pipeline(
callback=progress, callback=progress,
) )
dest = save_image(server, output, image, params, size, upscale=upscale, highres=highres) dest = save_image(
server, output, image, params, size, upscale=upscale, highres=highres
)
run_gc([job.get_device()]) run_gc([job.get_device()])
show_system_toast(f"finished txt2img job: {dest}") show_system_toast(f"finished txt2img job: {dest}")
@ -436,7 +438,9 @@ def run_img2img_pipeline(
callback=progress, callback=progress,
) )
dest = save_image(server, output, image, params, size, upscale=upscale, highres=highres) dest = save_image(
server, output, image, params, size, upscale=upscale, highres=highres
)
run_gc([job.get_device()]) run_gc([job.get_device()])
show_system_toast(f"finished img2img job: {dest}") show_system_toast(f"finished img2img job: {dest}")
@ -502,7 +506,9 @@ def run_inpaint_pipeline(
callback=progress, callback=progress,
) )
dest = save_image(server, outputs[0], image, params, size, upscale=upscale, border=border) dest = save_image(
server, outputs[0], image, params, size, upscale=upscale, border=border
)
del image del image
run_gc([job.get_device()]) run_gc([job.get_device()])

View File

@ -131,9 +131,12 @@ def save_image(
exif = PngImagePlugin.PngInfo() exif = PngImagePlugin.PngInfo()
if params is not None: if params is not None:
exif.add_text("Make", "onnx-web")
exif.add_text("Model", "TODO: server.version")
exif.add_text("Parameters", str_params(params, size)) exif.add_text("Parameters", str_params(params, size))
exif.add_text( exif.add_text(
"JSON Parameters", "JSON Parameters",
dumps(
json_params( json_params(
[output], [output],
params, params,
@ -141,6 +144,7 @@ def save_image(
upscale=upscale, upscale=upscale,
border=border, border=border,
highres=highres, highres=highres,
)
), ),
) )
@ -152,16 +156,36 @@ def save_image(
ExifIFD.UserComment: UserComment.dump( ExifIFD.UserComment: UserComment.dump(
str_params(params, size), encoding="unicode" str_params(params, size), encoding="unicode"
), ),
ExifIFD.MakerNote: UserComment.dump(
dumps(
json_params(
[output],
params,
size,
upscale=upscale,
border=border,
highres=highres,
)
),
encoding="unicode",
),
ImageIFD.Make: "onnx-web", ImageIFD.Make: "onnx-web",
ImageIFD.Model: "TODO", ImageIFD.Model: "TODO: server.version",
# TODO: add JSON params
} }
} }
) )
image.save(path, format=server.image_format, exif=exif) image.save(path, format=server.image_format, exif=exif)
if params is not None: if params is not None:
save_params(server, output, params, size, upscale=upscale, border=border, highres=highres) save_params(
server,
output,
params,
size,
upscale=upscale,
border=border,
highres=highres,
)
logger.debug("saved output image to: %s", path) logger.debug("saved output image to: %s", path)
return path return path