diff --git a/__init__.py b/__init__.py index b568427..d79bb68 100644 --- a/__init__.py +++ b/__init__.py @@ -30,7 +30,7 @@ NODE_CONFIG = { "CreateShapeMask": {"class": CreateShapeMask, "name": "Create Shape Mask"}, "CreateVoronoiMask": {"class": CreateVoronoiMask, "name": "Create Voronoi Mask"}, "CreateMagicMask": {"class": CreateMagicMask, "name": "Create Magic Mask"}, - "GetMaskSize": {"class": GetMaskSize, "name": "Get Mask Size"}, + "GetMaskSizeAndCount": {"class": GetMaskSizeAndCount, "name": "Get Mask Size & Count"}, "GrowMaskWithBlur": {"class": GrowMaskWithBlur, "name": "Grow Mask With Blur"}, "MaskBatchMulti": {"class": MaskBatchMulti, "name": "Mask Batch Multi"}, "OffsetMask": {"class": OffsetMask, "name": "Offset Mask"}, @@ -38,8 +38,9 @@ NODE_CONFIG = { "ResizeMask": {"class": ResizeMask, "name": "Resize Mask"}, "RoundMask": {"class": RoundMask, "name": "Round Mask"}, #images - "ColorMatch": {"class": ColorMatch, "name": "Color Match"}, "AddLabel": {"class": AddLabel, "name": "Add Label"}, + "ColorMatch": {"class": ColorMatch, "name": "Color Match"}, + "GetImageSizeAndCount": {"class": GetImageSizeAndCount, "name": "Get Image Size & Count"}, "ImageAndMaskPreview": {"class": ImageAndMaskPreview}, "ImageBatchMulti": {"class": ImageBatchMulti, "name": "Image Batch Multi"}, "ImageBatchTestPattern": {"class": ImageBatchTestPattern, "name": "Image Batch Test Pattern"}, diff --git a/nodes/image_nodes.py b/nodes/image_nodes.py index 96db37a..50648bf 100644 --- a/nodes/image_nodes.py +++ b/nodes/image_nodes.py @@ -28,7 +28,7 @@ class ImagePass: } RETURN_TYPES = ("IMAGE",) FUNCTION = "passthrough" - CATEGORY = "KJNodes/misc" + CATEGORY = "KJNodes/image" DESCRIPTION = """ Passes the image through without modifying it. """ @@ -455,7 +455,33 @@ ComfyUI/custom_nodes/ComfyUI-KJNodes/fonts combined_images = processed_batch return (combined_images,) + +class GetImageSizeAndCount: + @classmethod + def INPUT_TYPES(s): + return {"required": { + "image": ("IMAGE",), + }} + RETURN_TYPES = ("IMAGE","INT", "INT", "INT",) + RETURN_NAMES = ("image", "width", "height", "count",) + FUNCTION = "getsize" + CATEGORY = "KJNodes/masking" + DESCRIPTION = """ +Returns the width and height of the image, +and passes it through unchanged. + +""" + + def getsize(self, image): + width = image.shape[2] + height = image.shape[1] + count = image.shape[0] + return {"ui": { + "text": [f"{count}x{width}x{height}"]}, + "result": (image, width, height, count) + } + class ImageBatchRepeatInterleaving: RETURN_TYPES = ("IMAGE",) @@ -527,7 +553,7 @@ class ImageNormalize_Neg1_To_1: }} RETURN_TYPES = ("IMAGE",) FUNCTION = "normalize" - CATEGORY = "KJNodes/misc" + CATEGORY = "KJNodes/image" DESCRIPTION = """ Normalize the images to be in the range [-1, 1] """ diff --git a/nodes/mask_nodes.py b/nodes/mask_nodes.py index 6889279..a4cc38f 100644 --- a/nodes/mask_nodes.py +++ b/nodes/mask_nodes.py @@ -823,7 +823,7 @@ class CreateVoronoiMask: return (torch.stack(out, dim=0), 1.0 - torch.stack(out, dim=0),) -class GetMaskSize: +class GetMaskSizeAndCount: @classmethod def INPUT_TYPES(s): return {"required": { @@ -836,7 +836,7 @@ class GetMaskSize: CATEGORY = "KJNodes/masking" DESCRIPTION = """ Returns the width and height of the mask, -and passes through the mask unchanged. +and passes it through unchanged. """ diff --git a/web/js/jsnodes.js b/web/js/jsnodes.js index da34cd3..c09e893 100644 --- a/web/js/jsnodes.js +++ b/web/js/jsnodes.js @@ -74,18 +74,38 @@ app.registerExtension({ } break; - case "GetMaskSize": - const onConnectInput = nodeType.prototype.onConnectInput; + case "GetMaskSizeAndCount": + const onGetMaskSizeConnectInput = nodeType.prototype.onConnectInput; nodeType.prototype.onConnectInput = function (targetSlot, type, output, originNode, originSlot) { - const v = onConnectInput?.(this, arguments); + const v = onGetMaskSizeConnectInput?.(this, arguments); targetSlot.outputs[1]["name"] = "width" targetSlot.outputs[2]["name"] = "height" targetSlot.outputs[3]["name"] = "count" return v; } - const onExecuted = nodeType.prototype.onExecuted; + const onGetMaskSizeExecuted = nodeType.prototype.onExecuted; nodeType.prototype.onExecuted = function(message) { - const r = onExecuted? onExecuted.apply(this,arguments): undefined + const r = onGetMaskSizeExecuted? onGetMaskSizeExecuted.apply(this,arguments): undefined + let values = message["text"].toString().split('x').map(Number); + this.outputs[1]["name"] = values[1] + " width" + this.outputs[2]["name"] = values[2] + " height" + this.outputs[3]["name"] = values[0] + " count" + return r + } + break; + + case "GetImageSizeAndCount": + const onGetImageSizeConnectInput = nodeType.prototype.onConnectInput; + nodeType.prototype.onConnectInput = function (targetSlot, type, output, originNode, originSlot) { + const v = onGetImageSizeConnectInput?.(this, arguments); + targetSlot.outputs[1]["name"] = "width" + targetSlot.outputs[2]["name"] = "height" + targetSlot.outputs[3]["name"] = "count" + return v; + } + const onGetImageSizeExecuted = nodeType.prototype.onExecuted; + nodeType.prototype.onExecuted = function(message) { + const r = onGetImageSizeExecuted? onGetImageSizeExecuted.apply(this,arguments): undefined let values = message["text"].toString().split('x').map(Number); this.outputs[1]["name"] = values[1] + " width" this.outputs[2]["name"] = values[2] + " height"