Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Add ImageRotate and ImageFlip nodes. (#8789)

comfyanonymousf74fc4d9279b
diff --git a/comfy_extras/nodes_images.py b/comfy_extras/nodes_images.py
index ed54ccc57..fba80e2ae 100644
--- a/comfy_extras/nodes_images.py
+++ b/comfy_extras/nodes_images.py
@@ -583,6 +583,49 @@ class GetImageSize:
return width, height, batch_size
+class ImageRotate:
+ @classmethod
+ def INPUT_TYPES(s):
+ return {"required": { "image": (IO.IMAGE,),
+ "rotation": (["none", "90 degrees", "180 degrees", "270 degrees"],),
+ }}
+ RETURN_TYPES = (IO.IMAGE,)
+ FUNCTION = "rotate"
+
+ CATEGORY = "image/transform"
+
+ def rotate(self, image, rotation):
+ rotate_by = 0
+ if rotation.startswith("90"):
+ rotate_by = 1
+ elif rotation.startswith("180"):
+ rotate_by = 2
+ elif rotation.startswith("270"):
+ rotate_by = 3
+
+ image = torch.rot90(image, k=rotate_by, dims=[2, 1])
+ return (image,)
+
+class ImageFlip:
+ @classmethod
+ def INPUT_TYPES(s):
+ return {"required": { "image": (IO.IMAGE,),
+ "flip_method": (["x-axis: vertically", "y-axis: horizontally"],),
+ }}
+ RETURN_TYPES = (IO.IMAGE,)
+ FUNCTION = "flip"
+
+ CATEGORY = "image/transform"
+
+ def flip(self, image, flip_method):
+ if flip_method.startswith("x"):
+ image = torch.flip(image, dims=[1])
+ elif flip_method.startswith("y"):
+ image = torch.flip(image, dims=[2])
+
+ return (image,)
+
+
NODE_CLASS_MAPPINGS = {
"ImageCrop": ImageCrop,
"RepeatImageBatch": RepeatImageBatch,
@@ -594,4 +637,6 @@ NODE_CLASS_MAPPINGS = {
"ImageStitch": ImageStitch,
"ResizeAndPadImage": ResizeAndPadImage,
"GetImageSize": GetImageSize,
+ "ImageRotate": ImageRotate,
+ "ImageFlip": ImageFlip,
}