Remove rotation padding
Cleaning up after the rotate-align-generate-rotate-back dance
- original_image
- rotated_image
- image
This node exists to clean up a mess that rotation itself creates. When you rotate a rectangular image to straighten a tilted face, the canvas has to expand to fit the rotated content without cropping anything off - that's just how image rotation works. KpsRotate does the same expansion on keypoint data. Once you've generated against that expanded, straightened version and then rotated the result back to the original orientation, you're left with extra padding around the edges that wasn't in your source image. This node strips that padding back off so the output matches your original image's actual frame.
How it works
You give it the original_image (before any rotation happened) and the rotated_image (after the rotate-generate-rotate-back round trip), and it figures out how much extra canvas the rotation math added and trims it off, returning an image sized and positioned to match the original. It's a pure geometry/compositing step - no face detection, no InstantID-specific logic, just undoing the side effect of rotating a rectangle.
The inputs and outputs that matter
Only two inputs, both required:
original_image- the pose image exactly as it was before you rotated it to align the face.rotated_image- the generated (or otherwise processed) image, after it's been rotated back toward the original orientation.
One output: image, with the rotation-induced expansion removed.
Where this fits
This is specifically the last step in the auto-rotate pattern this pack's example workflows use (auto_rotate.json in the README): detect angle with AngleFromFace, rotate the pose image and its KPS to straighten the face, generate, rotate the result back to the original orientation, then run it through this node to trim off the padding both rotations introduced. If your workflow never rotates anything - face was already upright, or you're doing pure text-to-image generation from drawn KPS with no source photo to align - you don't need this node at all.
Install
ComfyUI Manager: search comfyui-instantId-faceswap. Manual: git clone https://github.com/nosiu/comfyui-instantId-faceswap into custom_nodes/, pip install -r requirements.txt. No model download needed - this node is pure image geometry, nothing InstantID-specific about its actual computation.
Common issues & troubleshooting
Output looks cropped or misaligned relative to the original. This node assumes rotated_image genuinely is the result of rotating original_image (directly or via a generation pass on the rotated version) by some angle and then rotating back - if the two images don't actually correspond to the same rotation round trip, the padding math has nothing consistent to trim against. Double-check both inputs are coming from the same rotate/generate/rotate-back chain, not mismatched images from different branches of your graph.
Not sure if you need this node in your workflow. You only need it if you're rotating images to straighten a face before generation and rotating them back afterward. If your pipeline never touches rotation - straight faceswap on an already-upright reference, or pure prompt-driven generation with hand-drawn KPS - skip it entirely; there's no padding to remove.
Edges still look slightly off after using this node. Rotation involves resampling pixels at non-integer angles, which introduces some unavoidable softening or interpolation artifacts near the border regardless of how cleanly the padding gets trimmed - that's a property of rotating images at arbitrary angles in general, not something this specific node can fix.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| original_image | IMAGE | — | |
| rotated_image | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |