ComfyUI Rotate Image

A pair of ComfyUI custom nodes for angle-based image rotation in processing pipelines. Rotate an image by any angle, run it through other nodes (inpainting, img2img, upscaling, …), then perfectly restore it to its original dimensions.


Nodes

🔄 Rotate Image

Rotates an IMAGE (and optional MASK) by a specified angle. The canvas is automatically expanded so no content is clipped, and new areas are filled with black. A ROTATION_INFO value is emitted so the paired Restore Rotated Image node can exactly reverse the transformation.

Inputs

Name Type Description
image IMAGE Input image
angle FLOAT Rotation angle in degrees (−360 to 360). Positive = counter-clockwise
interpolation COMBO Resampling algorithm — see table below
mask (optional) MASK Input mask — rotated with the same transformation

Outputs

Name Type Description
image IMAGE Rotated image with expanded black-filled canvas
mask MASK Rotated mask (or a black mask if none was provided)
rotation_info ROTATION_INFO Metadata required by Restore Rotated Image

↩️ Restore Rotated Image

Reverses the rotation applied by Rotate Image and crops the result back to the original image dimensions. Wire the rotation_info output of Rotate Image directly into this node.

Inputs

Name Type Description
image IMAGE Processed rotated image
rotation_info ROTATION_INFO Metadata from Rotate Image
mask (optional) MASK Processed mask to restore

Outputs

Name Type Description
image IMAGE Restored image, cropped to original dimensions
mask MASK Restored mask, cropped to original dimensions

Interpolation Algorithms

Choose the resampling method that best suits your use case:

Method Quality Speed Best For
NEAREST ★☆☆☆ ⚡⚡⚡⚡ Pixel art, binary masks
BILINEAR ★★☆☆ ⚡⚡⚡ Quick previews
BICUBIC ★★★☆ ⚡⚡ Photos — default
LANCZOS ★★★★ ⚡ Maximum quality (uses BICUBIC for the affine rotation step — PIL limitation)

Tip: Use LANCZOS or BICUBIC to avoid mosaic/pixelation artifacts on photographic content.


Typical Workflow

[Image] ──► Rotate Image ──► [KSampler / Inpaint / Upscale / …] ──► Restore Rotated Image ──► [Result]
                │                                                              ▲
                └──────────────── rotation_info ────────────────────────────►─┘
  1. Connect your source image to Rotate Image.
  2. Set the desired angle and interpolation.
  3. Wire the image (and optionally mask) outputs into your processing nodes.
  4. Wire the rotation_info output directly to Restore Rotated Image.
  5. Connect the processed image (and mask) from your pipeline into Restore Rotated Image.
  6. The restored output will have exactly the same dimensions as the original input.

Installation

Search for "Rotate Image" in the ComfyUI Manager and click Install.

Manual

cd ComfyUI/custom_nodes
git clone https://github.com/YOUR_USERNAME/comfyui-rotate-image

Restart ComfyUI. No additional dependencies are required — the nodes use only libraries already bundled with ComfyUI (torch, Pillow, numpy).


Notes

  • Batch support: Both nodes correctly handle batched images (multiple images in a single tensor).
  • Angle convention: Positive angles rotate counter-clockwise (PIL convention). Use negative angles for clockwise rotation.
  • 0° / 360°: The image is returned unchanged.
  • Size-altering pipelines: If your processing nodes change the image size (e.g. upscaling), Restore Rotated Image still performs the correct inverse rotation and crops to the original dimensions stored in rotation_info.
  • ROTATION_INFO type: This is a custom ComfyUI type — it can only be connected between a Rotate Image output and a Restore Rotated Image input.

License

MIT

S
Description
No description provided
Readme MIT
50 KiB
Languages
Python 100%