From 668e87f920be30001bb87214d9001bf59f2da275 Mon Sep 17 00:00:00 2001 From: DenOfEquity <166248528+DenOfEquity@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:32:20 +0100 Subject: [PATCH] keep user drawn foreground in img2img sub-tabs (#1666) preserve (flatten) user-drawn foregrounds from Sketch and Inpaint sketch tabs when copying --- modules/ui.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 9698002c..12ff507d 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -585,11 +585,17 @@ def create_ui(): for i, tab in enumerate(img2img_tabs): tab.select(fn=lambda tabnum=i: tabnum, inputs=[], outputs=[img2img_selected_tab]) + def copyCanvas_img2img (background, foreground, source): + if source == 1 or source == 3: # 1 is sketch, 3 is Inpaint sketch + bg = Image.alpha_composite(background, foreground) + return bg, None + return background, None + for button, name, elem in copy_image_buttons: button.click( - fn=lambda img: img, - inputs=[elem.background], - outputs=[copy_image_destinations[name].background], + fn=copyCanvas_img2img, + inputs=[elem.background, elem.foreground, img2img_selected_tab], + outputs=[copy_image_destinations[name].background, copy_image_destinations[name].foreground], ) button.click( fn=None,