[Feature Request] Save defaults for extras & keep image parameters after using extras #251
This commit is contained in:
parent
843b2b64fc
commit
482a6ce8cb
|
@ -13,6 +13,8 @@ cached_images = {}
|
||||||
def run_extras(image, gfpgan_visibility, codeformer_visibility, codeformer_weight, upscaling_resize, extras_upscaler_1, extras_upscaler_2, extras_upscaler_2_visibility):
|
def run_extras(image, gfpgan_visibility, codeformer_visibility, codeformer_weight, upscaling_resize, extras_upscaler_1, extras_upscaler_2, extras_upscaler_2_visibility):
|
||||||
devices.torch_gc()
|
devices.torch_gc()
|
||||||
|
|
||||||
|
existing_pnginfo = image.info or {}
|
||||||
|
|
||||||
image = image.convert("RGB")
|
image = image.convert("RGB")
|
||||||
info = ""
|
info = ""
|
||||||
|
|
||||||
|
@ -65,7 +67,7 @@ def run_extras(image, gfpgan_visibility, codeformer_visibility, codeformer_weigh
|
||||||
while len(cached_images) > 2:
|
while len(cached_images) > 2:
|
||||||
del cached_images[next(iter(cached_images.keys()))]
|
del cached_images[next(iter(cached_images.keys()))]
|
||||||
|
|
||||||
images.save_image(image, outpath, "", None, info=info, extension=opts.samples_format, short_filename=True, no_prompt=True, pnginfo_section_name="extras")
|
images.save_image(image, outpath, "", None, info=info, extension=opts.samples_format, short_filename=True, no_prompt=True, pnginfo_section_name="extras", existing_info=existing_pnginfo)
|
||||||
|
|
||||||
return image, plaintext_to_html(info), ''
|
return image, plaintext_to_html(info), ''
|
||||||
|
|
||||||
|
|
|
@ -247,7 +247,7 @@ def sanitize_filename_part(text, replace_spaces=True):
|
||||||
return text.translate({ord(x): '' for x in invalid_filename_chars})[:128]
|
return text.translate({ord(x): '' for x in invalid_filename_chars})[:128]
|
||||||
|
|
||||||
|
|
||||||
def save_image(image, path, basename, seed=None, prompt=None, extension='png', info=None, short_filename=False, no_prompt=False, pnginfo_section_name='parameters', p=None):
|
def save_image(image, path, basename, seed=None, prompt=None, extension='png', info=None, short_filename=False, no_prompt=False, pnginfo_section_name='parameters', p=None, existing_info=None):
|
||||||
# would be better to add this as an argument in future, but will do for now
|
# would be better to add this as an argument in future, but will do for now
|
||||||
is_a_grid = basename != ""
|
is_a_grid = basename != ""
|
||||||
|
|
||||||
|
@ -258,7 +258,9 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
|
||||||
else:
|
else:
|
||||||
file_decoration = opts.samples_filename_format or "[seed]-[prompt_spaces]"
|
file_decoration = opts.samples_filename_format or "[seed]-[prompt_spaces]"
|
||||||
|
|
||||||
file_decoration = "-" + file_decoration.lower()
|
if file_decoration != "":
|
||||||
|
file_decoration = "-" + file_decoration.lower()
|
||||||
|
|
||||||
if seed is not None:
|
if seed is not None:
|
||||||
file_decoration = file_decoration.replace("[seed]", str(seed))
|
file_decoration = file_decoration.replace("[seed]", str(seed))
|
||||||
if prompt is not None:
|
if prompt is not None:
|
||||||
|
@ -273,6 +275,11 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i
|
||||||
|
|
||||||
if extension == 'png' and opts.enable_pnginfo and info is not None:
|
if extension == 'png' and opts.enable_pnginfo and info is not None:
|
||||||
pnginfo = PngImagePlugin.PngInfo()
|
pnginfo = PngImagePlugin.PngInfo()
|
||||||
|
|
||||||
|
if existing_info is not None:
|
||||||
|
for k, v in existing_info.items():
|
||||||
|
pnginfo.add_text(k, v)
|
||||||
|
|
||||||
pnginfo.add_text(pnginfo_section_name, info)
|
pnginfo.add_text(pnginfo_section_name, info)
|
||||||
else:
|
else:
|
||||||
pnginfo = None
|
pnginfo = None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user