From 70841ac8d1069fce85aee161d34335ea7742b314 Mon Sep 17 00:00:00 2001 From: mymusise Date: Wed, 26 Jun 2024 15:36:07 +0800 Subject: [PATCH] Support single image input for ImageBatchMultiple Signed-off-by: mymusise --- image.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/image.py b/image.py index b50e622..3411f49 100644 --- a/image.py +++ b/image.py @@ -55,9 +55,9 @@ class ImageBatchMultiple: return { "required": { "image_1": ("IMAGE",), - "image_2": ("IMAGE",), "method": (["nearest-exact", "bilinear", "area", "bicubic", "lanczos"], { "default": "lanczos" }), }, "optional": { + "image_2": ("IMAGE",), "image_3": ("IMAGE",), "image_4": ("IMAGE",), "image_5": ("IMAGE",), @@ -67,25 +67,28 @@ class ImageBatchMultiple: FUNCTION = "execute" CATEGORY = "essentials/image batch" - def execute(self, image_1, image_2, method, image_3=None, image_4=None, image_5=None): - if image_1.shape[1:] != image_2.shape[1:]: - image_2 = comfy.utils.common_upscale(image_2.movedim(-1,1), image_1.shape[2], image_1.shape[1], method, "center").movedim(1,-1) - out = torch.cat((image_1, image_2), dim=0) + def execute(self, image_1, method, image_2=None, image_3=None, image_4=None, image_5=None): + images = [image_1] + if image_2 is not None: + if image_1.shape[1:] != image_2.shape[1:]: + image_2 = comfy.utils.common_upscale(image_2.movedim(-1,1), image_1.shape[2], image_1.shape[1], method, "center").movedim(1,-1) + images.append(image_2) if image_3 is not None: if image_1.shape[1:] != image_3.shape[1:]: image_3 = comfy.utils.common_upscale(image_3.movedim(-1,1), image_1.shape[2], image_1.shape[1], method, "center").movedim(1,-1) - out = torch.cat((out, image_3), dim=0) + images.append(image_3) if image_4 is not None: if image_1.shape[1:] != image_4.shape[1:]: image_4 = comfy.utils.common_upscale(image_4.movedim(-1,1), image_1.shape[2], image_1.shape[1], method, "center").movedim(1,-1) - out = torch.cat((out, image_4), dim=0) + images.append(image_4) if image_5 is not None: if image_1.shape[1:] != image_5.shape[1:]: image_5 = comfy.utils.common_upscale(image_5.movedim(-1,1), image_1.shape[2], image_1.shape[1], method, "center").movedim(1,-1) - out = torch.cat((out, image_5), dim=0) + images.append(image_5) - return (out,) + out = torch.cat(images, dim=0) + return (out, ) class ImageExpandBatch: