MaskCrop_YC
Crop exactly around a mask — padding, multiple-of-8 sizing, and a live preview of the box
- image
- crop_frame
- mask
- cropped_image
- cropped_mask
- crop_frame
- crop_frame_preview
- crop_coords
Most crop nodes ask you to type coordinates or drag a box. MaskCrop_YC inverts that: you give it a mask (your crop_frame) and it crops the image tightly around the mask's bounding box - with per-side padding and an optional round-to-multiple so the crop lands on a size the model actually likes. It's the "crop" half of the crop-edit-stitch inpainting pattern, and it's built for people who'd rather define what to crop than where.
The round-to-multiple part is the quietly important feature. Diffusion models are happiest at certain dimensions, and edit models in particular can shimmer if the region is off-pattern. Set round_to_multiple to 8 (or 16, or whatever your model's VAE likes) and the crop is nudged outward until it fits. No manual "is this a multiple of 8?" arithmetic on your part.
How it works
It binarizes the crop_frame mask, finds its bounding box, expands each side by its own padding (top_padding, bottom_padding, left_padding, right_padding, all defaulting to 50), then rounds the size up to a multiple of round_to_multiple. invert_mask flips the frame first (useful when your "mask" is actually the keep-out region). detection_method has exactly one value right now, mask_area - it's a placeholder for future methods, not a real choice.
An optional mask input gets cropped in lockstep with the image, so you keep your region mask aligned to the crop without any extra work.
The outputs
Five of them, and they're all worth knowing:
cropped_image- the crop itself.cropped_mask- the optional mask, cropped to match.crop_frame- the frame, cropped.crop_frame_preview- the original image with a red box marking the final crop area and a green box marking the unpadded mask bounds. This is your visual check, and it's the reason you won't blind-crop.crop_coords- aCOORDStuple(x_min, y_min, x_max, y_max).
That last output is the handoff: it plugs directly into MaskCropRestore_YC from the same pack, which pastes the edited crop back. MaskCrop_YC → edit → MaskCropRestore_YC is the full loop, and it matches the community's "Inpaint Crop → model → Inpaint Stitch" standard (the approach the inpainting knowledge doc credits with making the old "composite after inpainting" rule a property of the graph instead of a discipline).
Install
From ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes
Restart ComfyUI. Standard deps, no models. Found under "YCNode/Mask".
Gotchas
An empty crop_frame doesn't error - it returns the full image with a crop_coords of the whole frame, which is arguably the right graceful failure but easy to miss when debugging. And remember the padding is applied on top of the round-to-multiple, so your final box can be larger than the mask plus padding suggests; that's by design (rounding nudges outward). Check the crop_frame_preview once before you trust it in a loop.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| crop_frame | MASK | — | |
| top_padding | INT | 500–1000 | — |
| bottom_padding | INT | 500–1000 | — |
| left_padding | INT | 500–1000 | — |
| right_padding | INT | 500–1000 | — |
| round_to_multiple | INT | 81–64 | — |
| invert_mask | BOOLEAN | false | — |
| detection_method | COMBO | 1 options: mask_area | |
| maskopt | MASK | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| cropped_image | IMAGE | — |
| cropped_mask | MASK | — |
| crop_frame | MASK | — |
| crop_frame_preview | IMAGE | — |
| crop_coords | COORDS | — |