Nodes/ComfyUI-MaxedOut/Smart Crop by Mask MXD
ComfyUI Node

Smart Crop by Mask MXD

Crop to your subject, not to the center of the frame

By Maxed-Out-99·Created about a year ago·Updated 21 days ago· 9
Smart Crop by Mask MXD
  • image
  • mask
  • image

Stock ComfyUI crops to the center. That's fine when your subject is centered and worthless when it isn't. Smart Crop by Mask MXD is the one-trick node that fixes the second case: give it an image and a mask of the subject, and it slides a square crop window to center on the mask instead of the frame center. For a subject standing off to one side, that's the difference between a crop that frames them and a crop that cuts them in half.

It's the kind of small utility that earns its place the moment you need it - think face-crop pipelines, re-framing a subject for an I2V workflow, or prepping training crops where the model should focus on the character, not the empty background around them.

How it works

The node finds the mask's bounding box, computes its centroid, and centers a square crop window there - sliding horizontally and vertically as needed, per the description. If a mask is empty or the math lands awkwardly, it falls back to the frame center rather than failing. It processes each frame of an image batch against its corresponding mask, so it works on frame sequences too, not just single stills.

Inputs and outputs

  • image - the IMAGE to crop.
  • mask - the MASK locating the subject. The mask doesn't need to be tight or clean - just roughly marking where the subject is - since the node only uses it to find the centroid and a bounding box.

Output: the cropped image (same batch size, square, sized to the smaller of the input dimensions).

Installing it

Part of the ComfyUI-MaxedOut pack. ComfyUI Manager search Maxed Out, or:

cd ComfyUI\custom_nodes
git clone https://github.com/Maxed-Out-99/ComfyUI-MaxedOut.git

Restart ComfyUI. No extra dependencies, no model downloads - the mask comes from your workflow (background removal, detection, or a hand-painted mask).

The honest limits

The crop is square and sized to the smaller input dimension - that's the whole design, so don't ask it for a 4:3 or portrait crop. And it's mask-driven, not detection-driven: it has no idea what the subject is, so a stray mask blob in a corner will happily drag the crop toward it. If you're feeding it masks from a detector, a little dilation or a quick cleanup on the mask side goes a long way. Good mask in, good crop out.

Categoryimage/transform

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
maskMASK

Outputs (1)

NameTypeDescription
imageIMAGE