mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-07-11 09:57:12 +08:00
Add ImageRotate and ImageFlip nodes. (#8789)
This commit is contained in:
parent
ae26cd99b5
commit
f74fc4d927
@ -583,6 +583,49 @@ class GetImageSize:
|
|||||||
|
|
||||||
return width, height, batch_size
|
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 = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
"ImageCrop": ImageCrop,
|
"ImageCrop": ImageCrop,
|
||||||
"RepeatImageBatch": RepeatImageBatch,
|
"RepeatImageBatch": RepeatImageBatch,
|
||||||
@ -594,4 +637,6 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
"ImageStitch": ImageStitch,
|
"ImageStitch": ImageStitch,
|
||||||
"ResizeAndPadImage": ResizeAndPadImage,
|
"ResizeAndPadImage": ResizeAndPadImage,
|
||||||
"GetImageSize": GetImageSize,
|
"GetImageSize": GetImageSize,
|
||||||
|
"ImageRotate": ImageRotate,
|
||||||
|
"ImageFlip": ImageFlip,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user