Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callback postprocess_image_after_composite #14657

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,11 @@ def infotext(index=0, use_main_prompt=False):

image = apply_overlay(image, p.paste_to, overlay_image)

if p.scripts is not None:
pp = scripts.PostprocessImageArgs(image)
p.scripts.postprocess_image_after_composite(p, pp)
image = pp.image

if save_samples:
images.save_image(image, p.outpath_samples, "", p.seeds[i], p.prompts[i], opts.samples_format, info=infotext(i), p=p)

Expand Down
17 changes: 17 additions & 0 deletions modules/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ def postprocess_maskoverlay(self, p, ppmo: PostProcessMaskOverlayArgs, *args):

pass

def postprocess_image_after_composite(self, p, pp: PostprocessImageArgs, *args):
"""
Called for every image after it has been generated.
Same as postprocess_image but after inpaint_full_res composite
So that it operates on the full image instead of the inpaint_full_res crop region.
"""

pass

def postprocess(self, p, processed, *args):
"""
This function is called after processing ends for AlwaysVisible scripts.
Expand Down Expand Up @@ -856,6 +865,14 @@ def postprocess_maskoverlay(self, p, ppmo: PostProcessMaskOverlayArgs):
except Exception:
errors.report(f"Error running postprocess_image: {script.filename}", exc_info=True)

def postprocess_image_after_composite(self, p, pp: PostprocessImageArgs):
for script in self.alwayson_scripts:
try:
script_args = p.script_args[script.args_from:script.args_to]
script.postprocess_image_after_composite(p, pp, *script_args)
except Exception:
errors.report(f"Error running postprocess_image_after_composite: {script.filename}", exc_info=True)

def before_component(self, component, **kwargs):
for callback, script in self.on_before_component_elem_id.get(kwargs.get("elem_id"), []):
try:
Expand Down