Skip to content

Commit 4609fcd

Browse files
authored
add node - image compare (Comfy-Org#11343)
1 parent 6207f86 commit 4609fcd

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

comfy_api/latest/_io.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,18 @@ def _expand_schema_for_dynamic(out_dict: dict[str, Any], live_inputs: dict[str,
11131113
out_dict[input_type][finalized_id] = value
11141114
out_dict["dynamic_paths"][finalized_id] = finalize_prefix(curr_prefix, curr_prefix[-1])
11151115

1116+
@comfytype(io_type="IMAGECOMPARE")
1117+
class ImageCompare(ComfyTypeI):
1118+
Type = dict
1119+
1120+
class Input(WidgetInput):
1121+
def __init__(self, id: str, display_name: str=None, optional=False, tooltip: str=None,
1122+
socketless: bool=True):
1123+
super().__init__(id, display_name, optional, tooltip, None, None, socketless)
1124+
1125+
def as_dict(self):
1126+
return super().as_dict()
1127+
11161128
DYNAMIC_INPUT_LOOKUP: dict[str, Callable[[dict[str, Any], dict[str, Any], tuple[str, dict[str, Any]], str, list[str] | None], None]] = {}
11171129
def register_dynamic_input_func(io_type: str, func: Callable[[dict[str, Any], dict[str, Any], tuple[str, dict[str, Any]], str, list[str] | None], None]):
11181130
DYNAMIC_INPUT_LOOKUP[io_type] = func
@@ -1958,4 +1970,5 @@ def as_dict(self) -> dict:
19581970
"add_to_dict_v1",
19591971
"add_to_dict_v3",
19601972
"V3Data",
1973+
"ImageCompare",
19611974
]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import nodes
2+
3+
from typing_extensions import override
4+
from comfy_api.latest import IO, ComfyExtension
5+
6+
7+
class ImageCompare(IO.ComfyNode):
8+
"""Compares two images with a slider interface."""
9+
10+
@classmethod
11+
def define_schema(cls):
12+
return IO.Schema(
13+
node_id="ImageCompare",
14+
display_name="Image Compare",
15+
description="Compares two images side by side with a slider.",
16+
category="image",
17+
is_experimental=True,
18+
is_output_node=True,
19+
inputs=[
20+
IO.Image.Input("image_a", optional=True),
21+
IO.Image.Input("image_b", optional=True),
22+
IO.ImageCompare.Input("compare_view"),
23+
],
24+
outputs=[],
25+
)
26+
27+
@classmethod
28+
def execute(cls, image_a=None, image_b=None, compare_view=None) -> IO.NodeOutput:
29+
result = {"a_images": [], "b_images": []}
30+
31+
preview_node = nodes.PreviewImage()
32+
33+
if image_a is not None and len(image_a) > 0:
34+
saved = preview_node.save_images(image_a, "comfy.compare.a")
35+
result["a_images"] = saved["ui"]["images"]
36+
37+
if image_b is not None and len(image_b) > 0:
38+
saved = preview_node.save_images(image_b, "comfy.compare.b")
39+
result["b_images"] = saved["ui"]["images"]
40+
41+
return IO.NodeOutput(ui=result)
42+
43+
44+
class ImageCompareExtension(ComfyExtension):
45+
@override
46+
async def get_node_list(self) -> list[type[IO.ComfyNode]]:
47+
return [
48+
ImageCompare,
49+
]
50+
51+
52+
async def comfy_entrypoint() -> ImageCompareExtension:
53+
return ImageCompareExtension()

nodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,7 @@ async def init_builtin_extra_nodes():
23702370
"nodes_nop.py",
23712371
"nodes_kandinsky5.py",
23722372
"nodes_wanmove.py",
2373+
"nodes_image_compare.py",
23732374
]
23742375

23752376
import_failed = []

0 commit comments

Comments
 (0)