|
| 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() |
0 commit comments