Image Face Aspect Crop
Crop to an aspect ratio without decapitating the subject
- image
- cropped_image
- debug_image
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_imageshows no boxes, that's Haar being Haar, not your settings. Lowermin_face_percentandmin_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_neighborsand check the debug overlay. - Crop still cuts heads - raise
subject_top_biasandface_anchor_strength; ifmax_anchor_shift_ratiois low the crop can't travel far enough to follow the face.
Inputs (12)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| width | INT | 102416–8192 | — |
| height | INT | 57616–8192 | — |
| face_anchor_strength | FLOAT | 0.900–1 | — |
| center_bias_weight | FLOAT | 0.100–2 | — |
| subject_top_bias | FLOAT | 0.200–2 | — |
| secondary_face_weight | FLOAT | 0.150–2 | — |
| max_anchor_shift_ratio | FLOAT | 1.000.1–1 | — |
| detect_scale_factor | FLOAT | 1.101.01–1.5 | — |
| detect_min_neighbors | INT | 51–12 | — |
| min_face_percent | FLOAT | 3.00.5–40 | — |
| debug_printsopt | BOOLEAN | false | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| cropped_image | IMAGE | — |
| debug_image | IMAGE | — |