Nodes/comfyui-mask-util/Image Adaptive Crop With Mask
ComfyUI Node

Image Adaptive Crop With Mask

Crop to the Thing You Masked, Not the Whole Canvas

By longgui0318·Created 3 years ago·Updated about a year ago· 8
Image Adaptive Crop With Mask
  • image
  • mask
  • image
width512
height512
padding0

This is the "detect, crop, resample" trick that shows up all over serious ComfyUI workflows, just handed to you as one node instead of a chain of math nodes. You've got a mask - a face, a garment, a product, whatever region you actually care about - and instead of running your whole 2048px image through a sampler for the sake of one small detail, you crop down to just that region, run your pass on a focused, reasonably sized image, and get better results for less compute. Impact Pack's FaceDetailer made this pattern famous for faces; Image Adaptive Crop With Mask gives you the crop step on its own, usable for anything a mask can outline.

The inputs are image and mask (the region you want), plus three numbers a beginner will actually set: width and height (default 512×512, capped at 8096), which is your target output size, and padding (default 0, up to 1024), extra pixels added around the mask's bounding box so the crop doesn't hug the edge of your subject too tightly - useful when you're about to run a detail pass and want a bit of surrounding context for the sampler to blend into. The single output is image, the cropped result, sized and padded per your settings.

Where this fits in a real workflow: mask your subject (manually, or with a segmentation node), crop with this node, run your sampling/upscale/detail pass on the small crop, then composite the result back onto the original. For that last step, the community-favored move - per ComfyUI's own troubleshooting lore - is ImageCompositeMasked rather than a full VAE re-encode of the whole image, because every VAE encode/decode cycle is lossy and chained cycles visibly degrade color and detail over multiple passes. This node only handles the crop-out half; you'll want a paste-back node afterward if you want the detail applied in place rather than as a standalone cropped image.

Installing it: comfyui-mask-util comes from longgui0318, who's better known (such as it is) for comfyui-magic-clothing, a virtual-try-on wrapper that had a small spike of Reddit attention in 2024 and has gone quiet since. This pack reads as the general-purpose crop/resize/device glue spun out of that project. The GitHub README is essentially just the repo title - no written install guide, no usage notes - so treat everything here as read off the node definitions rather than official documentation.

Install via ComfyUI Manager (search "comfyui-mask-util") or manually:

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

Restart ComfyUI. No model downloads involved - this is crop/resize math on tensors you already have.

Where it bites: if your mask is mostly empty (a stray single pixel, or a mask that failed silently upstream and came through blank), the bounding box this node computes can end up degenerate - expect a crop that's tiny, off, or an outright error rather than something usable. Padding helps avoid a too-tight crop but won't fix a bad mask. And because width/height are a fixed target rather than "however big the masked region actually is," a very elongated mask (a tall thin object into a square target) will get squashed or stretched unless you've picked dimensions that roughly match your subject's real aspect ratio - this node won't warn you, it'll just resize to whatever you asked for.

Categoryimage

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
maskMASK
widthINT5120–8096
heightINT5120–8096
paddingINT00–1024

Outputs (1)

NameTypeDescription
imageIMAGE