Nodes/comfyui-mask-util/Image Adaptive Crop MASK&Resolution
ComfyUI Node

Image Adaptive Crop MASK&Resolution

Crop to a Mask and Get the Numbers to Paste It Back

By longgui0318·Created 3 years ago·Updated about a year ago· 8
Image Adaptive Crop MASK&Resolution
  • image
  • crop_mask
  • adaptive_croped_image
  • resolution_w
  • resolution_himage_multiple
  • expand_top
  • expand_buttom
  • expand_left
  • expand_right
  • crop_area_x
  • crop_area_y
  • crop_area_width
  • crop_area_height
  • INT
expand0
is_xl

This is the fuller-featured version of Image Adaptive Crop With Mask, and the extra output count is the whole point: it doesn't just crop, it hands back exactly the numbers you need to put the result back where it came from afterward. That's the piece a lot of simpler crop nodes skip - you crop for a detail pass, run your sampler, and then you're left doing the paste-back math yourself. This node does that bookkeeping for you.

The inputs are image and crop_mask (the region to crop to), expand (0–1024, extra padding around the mask's bounding box, same idea as "padding" in the simpler crop node), and is_xl (yes/no) - a nod to the fact that SDXL and SD1.5-family models like different native resolutions and aspect-ratio buckets, so the "adaptive" resolution this node picks depends on which family you're targeting. Get is_xl right and the crop comes out sized sensibly for your model instead of an arbitrary shape that needs another resize pass before it'll sample cleanly.

The outputs are where this earns its keep: adaptive_croped_image is the actual cropped result (yes, "croped" - that's how the node names it, worth knowing if you're hunting for it in a wire list). Alongside it you get resolution_w and resolution_himage_multiple (the target height it picked - the name is a typo in the node itself, not a mistake here), expand_top / expand_buttom / expand_left / expand_right (how much padding actually got applied on each side - near an image edge the expansion can't go the full amount in every direction, so this tells you the real, possibly asymmetric number rather than assuming your requested expand applied evenly), and crop_area_x / crop_area_y / crop_area_width / crop_area_height - the bounding box's actual position and size in the original image. That last group is exactly what you feed into a composite step to paste your processed crop back into the full-resolution original at the right spot, which is the same detect-crop-resample-paste-back pattern behind tools like Impact Pack's FaceDetailer, just exposed here as raw numbers instead of hidden inside one black-box node. There's also a twelfth output, a plain INT with no distinguishing name - the schema doesn't say what it represents, so don't assume; check it against your actual crop before building logic on it.

For the paste-back step itself, the community's preferred move (per ComfyUI's own troubleshooting lore) is compositing with something like ImageCompositeMasked at the coordinates this node gives you, rather than a full VAE re-encode of the whole image - every VAE cycle is lossy, and this node's whole reason for existing is to let you avoid unnecessary ones.

Installing it: part of comfyui-mask-util, from longgui0318 (also behind comfyui-magic-clothing, a virtual-try-on node with a brief 2024 spike of Reddit attention and little since). The GitHub README is just the project title, no usage docs, so everything here is read off the node's schema. Install via ComfyUI Manager (search "comfyui-mask-util") or:

cd ComfyUI/custom_nodes
git clone https://github.com/longgui0318/comfyui-mask-util

Restart ComfyUI. No model downloads needed.

Where it bites: a near-empty or noisy mask gives you a degenerate bounding box the same way it would with the simpler crop node - check your mask before trusting the output blindly. Get is_xl wrong and you'll get a technically valid crop sized for the wrong model family, which usually shows up as soft or oddly-composed results rather than an outright error, so it's an easy one to miss.

Categoryimage

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
crop_maskMASK
expandINT00–1024
is_xlCOMBO2 options: yes, no

Outputs (12)

NameTypeDescription
adaptive_croped_imageIMAGE
resolution_wINT
resolution_himage_multipleINT
expand_topINT
expand_buttomINT
expand_leftINT
expand_rightINT
crop_area_xINT
crop_area_yINT
crop_area_widthINT
crop_area_heightINT
INTINT