Nodes/ComfyUI_FaceAlignPaste/Face AutoFit Single @ CHAOS
ComfyUI Node

Face AutoFit Single @ CHAOS

The node that fixes your portrait framing before you ever sample

By CHAOSEA·Created about a year ago·Updated about a year ago· 24
Face AutoFit Single @ CHAOS
  • face_image
  • face_mask
  • image
  • mask
  • mode_code
modeportrait
backgroundwhite
move_x0
move_y0
face_size1.00
angle0.0
detection_methodinsightface
custom_width1024
custom_height1024

Here's the workflow problem this pack actually solves: you generate a character, the face is great, and the framing is wrong. Head too big for a portrait, cut off at the waist when you wanted full-body, floating in the middle of a 1024×1024 square with empty space around it. ComfyUI's default output size does not care about your composition. Face AutoFit Single is the fix - it takes a face (plus its mask), figures out where the eyes and head actually are, and pastes the person onto a canvas sized and framed for the kind of shot you want. It's the "compose first, generate later" node.

What it's for

This is the workhorse of the CHAOS portrait pipeline. The intended flow is: run AutoFit on a face to lay out a properly-framed canvas, feed the composed image and mask into your sampler as img2img or inpaint context, and generate the final character around the face you already like. The node does the geometry so you don't have to eyeball eye-line ratios in a text box. Lean on the KB's inpainting essay here: masked inpainting still owns bit-identical unmasked pixels, which is exactly why you want this node's mask output handed to a Set Mask / VAE Encode for Inpaint step rather than just sampling the whole thing.

How it works

It detects the face (default insightface, but opencv, mediapipe, dlib, auto, and none are all options - auto walks insightface → dlib → opencv → mediapipe until one clears its confidence bar, and none skips detection entirely and works from the mask alone). From the face it computes two ratios the author tuned against reference images: how much of the canvas height the head should occupy, and where the eye line should sit. Then it sizes the canvas for your chosen mode and composes the person onto it, with Lanczos interpolation so the paste stays crisp.

The built-in canvas sizes tell you what "framing" means here:

  • portrait → 1024×720
  • half_body → 1024×1536
  • full_body → 1280×1600
  • custom → whatever you set in custom_width/custom_height

Note the dimensions: portrait is landscape-ish, half-body is tall. These aren't arbitrary - they match the aspect ratios the author's reference compositions came from, so the head-to-canvas ratio lands where a portrait should.

Inputs and outputs that matter

The required inputs are the three you'll actually touch:

  • face_image and face_mask - the subject and its alpha. If you're coming from a generated image, a background-removal or segmentation node gives you the mask.
  • mode - portrait, half_body, full_body, or custom. This is the headline choice.
  • background - white or gray for the canvas behind the person.

The rest are tweaks: move_x/move_y (a −100..100 push around), face_size (0.5–2×), angle (−180..180°, for a slightly rotated subject), and detection_method.

Outputs are image (the composed canvas), mask (the composited alpha, ready to feed an inpaint encode), and mode_code (INT) - that last one is what you wire straight into a Prompt Selector Single node so the prompt matches the framing.

Installing it

All eight nodes come from one repo. ComfyUI Manager → search ComfyUI_FaceAlignPaste → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/CHAOSEA/ComfyUI_FaceAlignPaste

Restart, and the heavy lifting is the Python deps: insightface, dlib, mediapipe, opencv-python. InsightFace's buffalo_l weights auto-download on first use to ComfyUI/models/insightface/models (shared with IP-Adapter plus), and dlib's 68-landmark model ships inside the pack, so no extra model downloads. dlib itself compiles from source - expect a CMake + MSVC detour on Windows. And insightface's weights are non-commercial, fine for personal work.

Gotchas

  • First run downloads models. Don't panic when the first queue takes a minute; it's buffalo_l landing.
  • none detection relies on a good mask. If you pick none or the detector fails, the mask is all it has to find the head - a sloppy mask means a sloppy composition.
  • The mode_code contract. It only means something if you feed it to a CHAOS Prompt Selector. If you're not using that, ignore it.
  • It composes, it doesn't generate. The output is a flat canvas with a person pasted on it; you still need the sampler and inpainting to turn it into a finished image.
Categoryimage/face

Inputs (11)

NameTypeDefaultDescription
face_imageIMAGE
face_maskMASK
modeCOMBOportrait4 options: portrait, half_body, full_body, custom
backgroundCOMBOwhite2 options: white, gray
move_xFLOAT0-100–100
move_yFLOAT0-100–100
face_sizeFLOAT1.000.5–2
angleFLOAT0.0-180–180
detection_methodCOMBOinsightface6 options: insightface, auto, opencv, mediapipe, dlib, none
custom_widthoptINT1024256–4096
custom_heightoptINT1024256–4096

Outputs (3)

NameTypeDescription
imageIMAGE
maskMASK
mode_codeINT