Skip to content

Commit f74fc4d

Browse files
Add ImageRotate and ImageFlip nodes. (comfyanonymous#8789)
1 parent ae26cd9 commit f74fc4d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

comfy_extras/nodes_images.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,49 @@ def get_size(self, image, unique_id=None) -> tuple[int, int]:
583583

584584
return width, height, batch_size
585585

586+
class ImageRotate:
587+
@classmethod
588+
def INPUT_TYPES(s):
589+
return {"required": { "image": (IO.IMAGE,),
590+
"rotation": (["none", "90 degrees", "180 degrees", "270 degrees"],),
591+
}}
592+
RETURN_TYPES = (IO.IMAGE,)
593+
FUNCTION = "rotate"
594+
595+
CATEGORY = "image/transform"
596+
597+
def rotate(self, image, rotation):
598+
rotate_by = 0
599+
if rotation.startswith("90"):
600+
rotate_by = 1
601+
elif rotation.startswith("180"):
602+
rotate_by = 2
603+
elif rotation.startswith("270"):
604+
rotate_by = 3
605+
606+
image = torch.rot90(image, k=rotate_by, dims=[2, 1])
607+
return (image,)
608+
609+
class ImageFlip:
610+
@classmethod
611+
def INPUT_TYPES(s):
612+
return {"required": { "image": (IO.IMAGE,),
613+
"flip_method": (["x-axis: vertically", "y-axis: horizontally"],),
614+
}}
615+
RETURN_TYPES = (IO.IMAGE,)
616+
FUNCTION = "flip"
617+
618+
CATEGORY = "image/transform"
619+
620+
def flip(self, image, flip_method):
621+
if flip_method.startswith("x"):
622+
image = torch.flip(image, dims=[1])
623+
elif flip_method.startswith("y"):
624+
image = torch.flip(image, dims=[2])
625+
626+
return (image,)
627+
628+
586629
NODE_CLASS_MAPPINGS = {
587630
"ImageCrop": ImageCrop,
588631
"RepeatImageBatch": RepeatImageBatch,
@@ -594,4 +637,6 @@ def get_size(self, image, unique_id=None) -> tuple[int, int]:
594637
"ImageStitch": ImageStitch,
595638
"ResizeAndPadImage": ResizeAndPadImage,
596639
"GetImageSize": GetImageSize,
640+
"ImageRotate": ImageRotate,
641+
"ImageFlip": ImageFlip,
597642
}

0 commit comments

Comments
 (0)