Preprocess image for instantId
Crop, pad, resize, and build your control image in one go
- image
- mask
- insightface
- resized_image
- mask
- control_image
- x
- y
- original_width
- original_height
- new_width
- new_height
This is the node most InstantID faceswap workflows in this pack actually start from, once you've got a pose image and a mask drawn on it. It does three things at once: crops out the masked region (padded so there's context around the face), resizes that crop to dimensions InstantID can actually use, and - if you feed it an insightface app - builds the keypoint control image that ControlNetInstantIdApply needs downstream. One node, does most of the prep work.
How it works
You draw a mask over the face (and anything else you want to change - hair, a hat, whatever) on your pose image. This node finds the masked area, wraps it in a square, enlarges that square by pad pixels in every direction, then resizes the result down to multiples of 8 - SDXL's usual requirement. If you pass it an insightface input, it also runs face detection on that crop and generates a control_image: the rendered keypoint map InstantID's ControlNet actually conditions on. Skip the insightface input and this node still works fine as a general-purpose inpaint crop-and-resize utility, no InstantID-specific behavior required.
The inputs and outputs that matter
image/mask- your pose photo and the region you want to change. The mask has to actually contain the face for this to make sense.width/height(both default 1024) - target size, interpreted according toresize_mode.resize_mode- four options:auto(calculates size so the area matches width×height - the README's recommendation for SDXL iswidth: 1024, height: 1024with this mode),free(uses your exact width/height),scale by width,scale by height(derives the other dimension from aspect ratio).pad(default 100) - how far to expand the mask's bounding square in each direction before cropping. Too tight and insightface can't find enough face context; too loose and you're wasting resolution on background.insightface(optional) - feed this to get acontrol_imageout; omit it to use this purely as an inpaint-crop tool.
Outputs beyond the obvious resized_image, mask, and control_image: x, y, original_width, original_height, new_width, new_height - the geometry you need to composite your result back into the original full-size image afterward.
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. If you're using the insightface input, you need antelopev2 downloaded into models/insightface/models/antelopev2 first - this node calls into the same detection pipeline as LoadInsightface feeds elsewhere.
There's also an "Advanced" sibling node in this pack (not covered here) with per-edge padding and a choice of upscale method, if this node's single pad value doesn't give you enough control.
Common issues & troubleshooting
"No face detected in pose image." This is the pack's own most-cited error, and it happens right here when the insightface input can't find a usable face in your masked, padded crop. The README's own fixes, in order of how often people reach for them: draw a bigger mask, bump pad up so more context is included, or - if the face is at an extreme angle insightface just can't handle - skip detection entirely and draw your own keypoints with KpsDraw instead.
Control image looks wrong or the face is at a weird angle. The README flags this directly: at extreme rotation angles, the control_image this node builds can come out drawn incorrectly, because insightface's landmark detection gets unreliable past a certain tilt. AngleFromFace exists specifically to catch and correct for this before it becomes a problem.
Output resolution isn't what you expected. Remember auto mode targets area, not exact width/height - if you need precise pixel dimensions, use free instead.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| width | INT | 10240–16384 | — |
| height | INT | 10240–16384 | — |
| resize_mode | COMBO | 4 options: auto, free, scale by width, scale by height | |
| pad | INT | 1000–16384 | — |
| insightfaceopt | INSIGHTFACE_APP | — |
Outputs (9)
| Name | Type | Description |
|---|---|---|
| resized_image | IMAGE | — |
| mask | MASK | — |
| control_image | IMAGE | — |
| x | INT | — |
| y | INT | — |
| original_width | INT | — |
| original_height | INT | — |
| new_width | INT | — |
| new_height | INT | — |