Nodes/ComfyUI illumorae/Image Face Aspect Crop
ComfyUI Node

Image Face Aspect Crop

Crop to an aspect ratio without decapitating the subject

By CorvaeOboro·Created 8 months ago·Updated 6 days ago· 1
Image Face Aspect Crop
  • image
  • cropped_image
  • debug_image
width1024
height576
face_anchor_strength0.90
center_bias_weight0.10
subject_top_bias0.20
secondary_face_weight0.15
max_anchor_shift_ratio1.00
detect_scale_factor1.10
detect_min_neighbors5
min_face_percent3.0
debug_printsfalse

Plain center-cropping an image to a target aspect ratio is a gamble: if the subject isn't dead center, you crop off exactly the part you needed. Image Face Aspect Crop fixes the obvious blind spot - it detects faces in the image and anchors the crop box around the largest one, so you can reshape a portrait to 16:9 (or anything else) without the face sliding out of frame. It's the difference between "crop to 1024×576" and "crop to 1024×576 and keep the person in it."

Where this pays off fast: prepping source images for video (image-to-video wants specific aspect ratios and hates cut-off subjects), building consistent training/crop datasets, or batch-processing a folder of photos into a uniform format where center-crop would butcher half of them. It also emits a debug overlay so you can actually verify what it decided.

How it works

Face detection here is deliberately lightweight: OpenCV's bundled Haar cascade (the same haarcascade_frontalface_default.xml that ships with OpenCV), run on the CPU. No neural model, no VRAM cost, no download. The node finds all faces, sorts by area, and computes a crop anchor that blends the biggest face's position with a few bias terms - face_anchor_strength (default 0.9) says "anchor hard on the face," center_bias_weight (0.1) pulls toward the middle, subject_top_bias (0.2) nudges up so you don't leave the forehead behind, and secondary_face_weight (0.15) lets a second face tug the crop so it doesn't cut a companion off. max_anchor_shift_ratio caps how far the crop box is allowed to travel from center.

The detection dials (detect_scale_factor 1.1, detect_min_neighbors 5, min_face_percent 3) are the standard Haar knobs - min_neighbors up for fewer false positives, down if real faces are being ignored. width/height are the target crop dimensions (16–8192). debug_prints adds console logging.

Outputs are two images: cropped_image (the actual crop) and debug_image - an overlay showing the crop box and detected faces. Wire debug_image to a preview while you tune, then swap it out. This debug output is the single best feature: crop nodes that decide "wrong" silently are the worst kind of bug, and this one shows its work.

Installing it

Part of CorvaeOboro's ComfyUI_illumorae (CC0, no model downloads - the Haar cascade ships inside OpenCV). ComfyUI Manager → search illumorae, or:

cd ComfyUI/custom_nodes
git clone https://github.com/CorvaeOboro/ComfyUI_illumorae

Common issues

  • Faces not detected - Haar is a 2001-era detector: it likes frontal, well-lit faces and struggles with profiles, small faces, heavy angles, or faces turned away. If debug_image shows no boxes, that's Haar being Haar, not your settings. Lower min_face_percent and min_neighbors, or fall back to center crop.
  • False positives on furniture/background - Haar famously locks onto things that vaguely look like a face. Raise min_neighbors and check the debug overlay.
  • Crop still cuts heads - raise subject_top_bias and face_anchor_strength; if max_anchor_shift_ratio is low the crop can't travel far enough to follow the face.
Categoryillumorae

Inputs (12)

NameTypeDefaultDescription
imageIMAGE
widthINT102416–8192
heightINT57616–8192
face_anchor_strengthFLOAT0.900–1
center_bias_weightFLOAT0.100–2
subject_top_biasFLOAT0.200–2
secondary_face_weightFLOAT0.150–2
max_anchor_shift_ratioFLOAT1.000.1–1
detect_scale_factorFLOAT1.101.01–1.5
detect_min_neighborsINT51–12
min_face_percentFLOAT3.00.5–40
debug_printsoptBOOLEANfalse

Outputs (2)

NameTypeDescription
cropped_imageIMAGE
debug_imageIMAGE