Skip to content

Commit c5a6d28

Browse files
committed
add node - image compare
1 parent 908fd7d commit c5a6d28

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
],
23+
outputs=[],
24+
)
25+
26+
@classmethod
27+
def execute(cls, image_a=None, image_b=None) -> IO.NodeOutput:
28+
result = {"a_images": [], "b_images": []}
29+
30+
preview_node = nodes.PreviewImage()
31+
32+
if image_a is not None and len(image_a) > 0:
33+
saved = preview_node.save_images(image_a, "comfy.compare.a")
34+
result["a_images"] = saved["ui"]["images"]
35+
36+
if image_b is not None and len(image_b) > 0:
37+
saved = preview_node.save_images(image_b, "comfy.compare.b")
38+
result["b_images"] = saved["ui"]["images"]
39+
40+
return IO.NodeOutput(ui=result)
41+
42+
43+
class ImageCompareExtension(ComfyExtension):
44+
@override
45+
async def get_node_list(self) -> list[type[IO.ComfyNode]]:
46+
return [
47+
ImageCompare,
48+
]
49+
50+
51+
async def comfy_entrypoint() -> ImageCompareExtension:
52+
return ImageCompareExtension()

nodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,6 +2359,7 @@ async def init_builtin_extra_nodes():
23592359
"nodes_nop.py",
23602360
"nodes_kandinsky5.py",
23612361
"nodes_wanmove.py",
2362+
"nodes_image_compare.py",
23622363
]
23632364

23642365
import_failed = []

0 commit comments

Comments
 (0)