diff --git a/__init__.py b/__init__.py index f47c110..bd82a69 100644 --- a/__init__.py +++ b/__init__.py @@ -45,6 +45,7 @@ NODE_CONFIG = { "GetImageRangeFromBatch": {"class": GetImageRangeFromBatch, "name": "Get Image Range From Batch"}, "GetImageSizeAndCount": {"class": GetImageSizeAndCount, "name": "Get Image Size & Count"}, "ImageAndMaskPreview": {"class": ImageAndMaskPreview}, + "ImageAddMulti": {"class": ImageAddMulti, "name": "Image Add Multi"}, "ImageBatchMulti": {"class": ImageBatchMulti, "name": "Image Batch Multi"}, "ImageBatchRepeatInterleaving": {"class": ImageBatchRepeatInterleaving}, "ImageBatchTestPattern": {"class": ImageBatchTestPattern, "name": "Image Batch Test Pattern"}, diff --git a/nodes/image_nodes.py b/nodes/image_nodes.py index 2a089e1..ddc51d5 100644 --- a/nodes/image_nodes.py +++ b/nodes/image_nodes.py @@ -1134,6 +1134,50 @@ with the **inputcount** and clicking update. for c in range(1, inputcount): new_image = kwargs[f"image_{c + 1}"] image, = image_batch_node.batch(image, new_image) + return (image,) + +class ImageAddMulti: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "inputcount": ("INT", {"default": 2, "min": 2, "max": 1000, "step": 1}), + "image_1": ("IMAGE", ), + "image_2": ("IMAGE", ), + "blending": ( + [ 'add', + 'subtract', + 'multiply', + 'difference', + ], + { + "default": 'add' + }), + }, + } + + RETURN_TYPES = ("IMAGE",) + RETURN_NAMES = ("images",) + FUNCTION = "add" + CATEGORY = "KJNodes/image" + DESCRIPTION = """ +Add blends multiple images together. +You can set how many inputs the node has, +with the **inputcount** and clicking update. +""" + + def add(self, inputcount, blending, **kwargs): + image = kwargs["image_1"] + for c in range(1, inputcount): + new_image = kwargs[f"image_{c + 1}"] + if blending == "add": + image = torch.add(image * 0.5, new_image * 0.5) + elif blending == "subtract": + image = torch.sub(image * 0.5, new_image * 0.5) + elif blending == "multiply": + image = torch.mul(image * 0.5, new_image * 0.5) + elif blending == "difference": + image = torch.sub(image, new_image) return (image,) class PreviewAnimation: diff --git a/web/js/jsnodes.js b/web/js/jsnodes.js index b805706..c8fe533 100644 --- a/web/js/jsnodes.js +++ b/web/js/jsnodes.js @@ -30,6 +30,7 @@ app.registerExtension({ } break; case "ImageBatchMulti": + case "ImageAddMulti": nodeType.prototype.onNodeCreated = function () { this._type = "IMAGE" this.inputs_offset = nodeData.name.includes("selective")?1:0