🔄 AGSoft Image Rotate & Flip
Rotate an image, and take its mask along for the ride
- image
- mask
- image
- mask
- width
- height
Rotating an image in ComfyUI is easy. Rotating an image and its mask together, so they don't end up pointing at different things, is the part the stock nodes make you handle yourself. AGSoft Image Rotate & Flip does both in one shot - rotate the image, flip it, and any mask you've attached gets the identical transform.
That "sync" is the whole reason this node exists, and it matters more than it sounds. Flip a portrait for composition and forget to flip the mask, and suddenly your inpaint region is over the wrong ear. This node closes that failure mode by construction.
How it works
Give it an image, optionally a mask, and pick your transform. The controls:
angle_degrees- rotation in degrees, -360 to 360. Positive is counter-clockwise, per the tooltip, so 90 turns it one way and -90 the other. For the common cases there's arotation_presetdropdown (none/90/180/270/360) that overrides the numeric angle - handy when you want a hard 90 and don't want to argue with your fingers about the sign.flip_mode-none,horizontal, orvertical. Applied after rotation, which is the order you want: rotate to correct orientation, then mirror if the subject's facing the wrong way.interpolation-nearestorbilinear. The node's own docs are blunt here: only these two work reliably on tensors. Bilinear for photos, nearest if you're rotating a hard-edged mask-heavy composite.background_color- fills whatever shows through when the rotated canvas doesn't cover the full frame.transparentis the default and adds an alpha channel when needed; pickblackorwhiteif a solid background is what your downstream node expects.expand- grow the canvas so a rotated image doesn't clip its corners. Leave it off and a 45° rotation shaves the corners off; turn it on and you get the whole rotated rectangle, at the cost of a larger frame.
The mask input is optional, and here's the nice detail: the mask is always resampled with nearest interpolation regardless of what you set for the image. That's deliberate - a mask is binary-ish and bilinear would smear its edges into gray fuzz, which poisons inpaint weighting downstream.
Outputs
image, mask, width, height. The dimensions change when you rotate 90° or enable expand, so having them handed back is the difference between "I'll figure it out" and wiring the real size into an Empty Latent.
Installation
Part of the comfyui-AGSoft pack:
cd ComfyUI/custom_nodes
git clone https://github.com/Art-xmaster/comfyui-AGSoft.git
# restart ComfyUI
Or via ComfyUI Manager, search "comfyui-AGSoft". numpy + opencv-python dependencies, no models to download.
Where people get burned
Two things. First, the sign convention: positive = counter-clockwise. If your image ends up rotated the wrong way, that's the first thing to check - flip the sign or use the preset. Second, forgetting expand when you're rotating something that should keep its full contents; the corners get quietly trimmed and you may not notice until the subject's missing a hand. And if you're rotating a frame in an animation or video pipeline, remember this works on a single image at a time - feed it a batched IMAGE and it rotates the whole batch, which is usually what you want for stills but rarely what you want for video.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| angle_degrees | INT | 0-360–360 | Угол поворота в градусах. Положительное значение — против часовой стрелки. |
| interpolation | COMBO | bilinear | Алгоритм сглаживания для изображения. Только эти два метода стабильно работают с тензорами. |
| background_color | COMBO | transparent | Цвет заполнения пустых зон. 'transparent' добавляет альфа-канал при необходимости. |
| expand | BOOLEAN | false | Расширяет холст, чтобы избежать обрезки краёв изображения при повороте. |
| maskopt | MASK | Опциональная маска. Будет трансформирована синхронно с изображением (поворот, отражение, expand). Для маски всегда используется интерполяция 'nearest'. | |
| rotation_presetopt | COMBO | none | Быстрый выбор угла. Переопределяет значение angle_degrees. |
| flip_modeopt | COMBO | none | Зеркальное отражение. Применяется после поворота. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| width | INT | — |
| height | INT | — |