Nodes/ComfyUI_AIIA/AIIA Image Smart Crop
ComfyUI Node

AIIA Image Smart Crop

Smart Crop Before the Talking-Head Nodes, So Faces Actually Fit

By havvk·Created about a year ago·Updated 6 months ago· 13
AIIA Image Smart Crop
  • image
  • IMAGE
width512
height512
crop_basis
aspect_ratiooriginal
custom_aspect_ratio1.00
position
offset_x0.00
offset_y0.00

If your talking-head video comes out with the mouth weirdly huge or the face drifting out of frame, the problem is usually upstream of the generation - your input image was framed wrong. AIIA Image Smart Crop is a flexible crop/resize node that the README specifically positions before Ditto or other video samplers, to get faces centered and sized right before the model ever sees them. It's a utility, but it's the kind that quietly decides whether your avatar looks right.

How it works

Nothing AI about it - it's clean crop math on an IMAGE tensor. You give it a target and it computes a crop window from an anchor position, then resizes. The cleverness is the crop_basis system, which controls which edge is the anchor:

  • custom_size - force the exact width × height you specify.
  • fixed_width / fixed_height - lock one edge at your width/height, let the other adapt to the aspect ratio.
  • fixed_long_side - crop so the long side matches the original long side (ignores width/height). Keeps as much resolution as possible.
  • fixed_short_side - crop to the short side of the source. This is the "maximum crop" mode, useful when you want to punch way in on the face.

aspect_ratio then sets the shape - original, presets like 1:1, 4:3, 16:9, 9:16, 21:9, or custom with your own custom_aspect_ratio number. If the source image is portrait but your video is 16:9, this node handles the reframe in one go.

The inputs that matter

  • position - a 9-grid anchor: center, top, bottom, left, right, and the four corners. For a talking-head reference, center on a face-cropped photo is usually right.
  • offset_x / offset_y - relative fine-tuning of the anchor, from -1.0 to 1.0. If the crop keeps cutting off the top of the head, nudge offset_y negative to shift the window up.
  • width / height - only meaningful with custom_size (or as the fixed edge for fixed_width/fixed_height). Values are stepped to multiples of 8, which keeps the result friendly for latent-space work.

Output is the single cropped/resized IMAGE - straight into AIIA Ditto Sampler's ref_image, or anywhere else you need a specific aspect ratio.

When you actually need it

The sweet spot is pre-processing for video samplers: a square, centered face with minimal background makes Ditto's crop_scale behave, since the model's face-context window then contains mostly face. It's also handy for normalizing mixed-source images to a uniform resolution before batching, or punching a 9:16 vertical crop out of a landscape still for social clips. It won't detect the face for you - that's position and offset, manually - but for a node with zero dependencies and zero model downloads, it's a lot of control.

Install

Standard pack install: havvk/ComfyUI_AIIA via ComfyUI Manager or git clone https://github.com/havvk/ComfyUI_AIIA.git into custom_nodes/, restart. No models, no extra deps - it's pure Pillow math under the hood, so it just works.

CategoryAIIA/Image

Inputs (9)

NameTypeDefaultDescription
imageIMAGE
widthINT5120–8192
heightINT5120–8192
crop_basisCOMBO5 options: custom_size, fixed_width, fixed_height, fixed_long_side, fixed_short_side
aspect_ratioCOMBOoriginal9 options: original, custom, 1:1, 4:3, 3:4, 16:9, +3
custom_aspect_ratioFLOAT1.000.1–10
positionCOMBO9 options: center, top, bottom, left, right, top_left, +3
offset_xFLOAT0.00-1–1
offset_yFLOAT0.00-1–1

Outputs (1)

NameTypeDescription
IMAGEIMAGE