# 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 ### Via ComfyUI Manager (recommended) Search for **"Rotate Image"** in the [ComfyUI Manager](https://github.com/ltdrdata/ComfyUI-Manager) and click Install. ### Manual ```bash 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](LICENSE)