Skip to content
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
34 changes: 33 additions & 1 deletion comfy_extras/nodes_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import torch
import comfy.utils

from comfy.comfy_types import FileLocator
from comfy.comfy_types import FileLocator, IO
from server import PromptServer

MAX_RESOLUTION = nodes.MAX_RESOLUTION

Expand Down Expand Up @@ -491,6 +492,36 @@ def replacement(match):
counter += 1
return { "ui": { "images": results } }

class GetImageSize:

@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image": (IO.IMAGE,),
},
"hidden": {
"unique_id": "UNIQUE_ID",
}
}

RETURN_TYPES = (IO.INT, IO.INT)
RETURN_NAMES = ("width", "height")
FUNCTION = "get_size"

CATEGORY = "image"
DESCRIPTION = """Returns width and height of the image, and passes it through unchanged."""

def get_size(self, image, unique_id=None) -> tuple[int, int]:
height = image.shape[1]
width = image.shape[2]

# Send progress text to display size on the node
if unique_id:
PromptServer.instance.send_progress_text(f"width: {width}, height: {height}", unique_id)

return width, height

NODE_CLASS_MAPPINGS = {
"ImageCrop": ImageCrop,
"RepeatImageBatch": RepeatImageBatch,
Expand All @@ -500,4 +531,5 @@ def replacement(match):
"SaveAnimatedPNG": SaveAnimatedPNG,
"SaveSVGNode": SaveSVGNode,
"ImageStitch": ImageStitch,
"GetImageSize": GetImageSize,
}
1 change: 1 addition & 0 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,7 @@ def expand_image(self, image, left, top, right, bottom, feathering):
"ImageQuantize": "Image Quantize",
"ImageSharpen": "Image Sharpen",
"ImageScaleToTotalPixels": "Scale Image to Total Pixels",
"GetImageSize": "Get Image Size",
# _for_testing
"VAEDecodeTiled": "VAE Decode (Tiled)",
"VAEEncodeTiled": "VAE Encode (Tiled)",
Expand Down
5 changes: 4 additions & 1 deletion tests-unit/comfy_extras_test/image_stitch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
mock_nodes = MagicMock()
mock_nodes.MAX_RESOLUTION = 16384

with patch.dict('sys.modules', {'nodes': mock_nodes}):
# Mock server module for PromptServer
mock_server = MagicMock()

with patch.dict('sys.modules', {'nodes': mock_nodes, 'server': mock_server}):
from comfy_extras.nodes_images import ImageStitch


Expand Down
Loading