Crop By Mask
Auto-crop to your mask's bounding box, padded, so you can inpaint at full resolution
- image
- mask
- image
- mask
- crop_x
- crop_y
- original_width
- original_height
What it is
This is the front half of ComfyUI-InpaintEasy's crop → inpaint → merge pattern, and it's solving the same problem Impact Pack's FaceDetailer and the whole "only masked" inpainting mode solve: a small fix region buried in a big image gets almost no generation budget if you just sample the whole frame. A 64px eye in a 1024px image gets 64px worth of the model's attention and comes out mush. Crop by mask finds your masked region, pads it out, and crops both image and mask down to just that area - so whatever you sample next gets the full resolution budget instead of a sliver of it.
It's a manual-config cousin of the auto-crop step inside bigger crop-and-stitch pipelines, just without the "stitcher" bundle those use - here you get plain crop coordinates back instead, which you feed forward by hand.
How it works
Give it an image and a mask. It computes the mask's bounding box, expands it outward by your padding amount on each side, and crops both the image and the mask to that padded rectangle. Alongside the crop itself, it hands back the numbers you'll need later to put the result back where it came from - this node has no idea what you're going to do with the crop, so it just gives you everything required to reverse the operation once you're done.
The inputs and outputs that matter
padding- 0 to 512, default 64, step 8. This is context margin around the mask, not extra masked area. Too little and the model has nothing but the object itself to reference, which tends to produce visible seams at the crop edge. Too much and you're wasting resolution on pixels outside the region you actually care about. 32-64px is the range this defaults toward and it's a reasonable starting point for face/hand-scale fixes; scale it up for bigger regions.
The four extra outputs beyond the cropped image and mask - crop_x, crop_y, original_width, original_height - exist for exactly one reason: they're what Image Crop Merge needs to paste your processed crop back into the right spot at the right scale. Route them straight there; you shouldn't need to touch them yourself.
Typical chain: Crop By Mask → (optionally) Image and Mask Resize to hit your model's native resolution → your sampler, or Inpaint Model if you're feeding conditioning through it → Image Crop Merge with the coordinates carried over from here.
Installing it
ComfyUI Manager: search "ComfyUI-InpaintEasy" and install, or clone it by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/CY-CHENYUE/ComfyUI-InpaintEasy
Restart ComfyUI. No models to download - this is pure crop math, it doesn't touch a checkpoint or VAE at all.
Common issues
Crop is empty or tiny. Your mask is probably near-blank - this node crops to the mask's bounding box, so if nothing (or almost nothing) is painted, you get a degenerate crop. Check the mask upstream actually has meaningful coverage before this node.
Seam visible where the crop rejoins the image. Usually not this node's fault directly - bump padding so the model has more surrounding context to blend against, and make sure the mask itself has some blur on it (via Image and Mask Resize's mask_blur_radius) before you sample. Crop By Mask gives you the region; the softness of the eventual blend is decided elsewhere in the chain.
Crop looks right but the merge step pastes it in the wrong place. Make sure crop_x, crop_y, original_width, and original_height are actually wired through to Image Crop Merge unchanged - if anything resizes the image in between without carrying these numbers forward correctly, the paste-back math goes wrong.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| padding | INT | 640–512 | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| crop_x | INT | — |
| crop_y | INT | — |
| original_width | INT | — |
| original_height | INT | — |