CNP Crop
The mask-bbox crop node that does the tile math so you don't
- image
- mask
- cropped_image
- cropped_mask
- pipe
Every inpainting or detailing workflow eventually needs the same thing: crop exactly around what's masked, at a resolution the model can actually render. The built-in way is to hand-wire ImageCompositeMasked and crop nodes and do the coordinate math yourself, and the math is exactly the part that eats your afternoon. CNP Crop is the tiny single-file node that takes an image and a mask and gives you a clean, padded, correctly-sized crop - it's the "crop" half of the crop-and-paste pair this pack ships, with a sibling node doing the paste half.
There's nothing to download beyond the node itself: no models, no checkpoints, no API key. It's a 239-line file over torch/numpy/Pillow, which every ComfyUI install already has. That minimalism is the selling point - it's the kind of node you reach for when you don't want to assemble five core nodes and a calculator to do one job.
How it works
CNP Crop looks at your mask, finds the bounding box of its non-zero pixels, and cuts the image to it. Then three refinements happen, and they're the reason you'd use this instead of doing it by hand:
- Padding. You add context around the subject in
padding_pixels(absolute) orpadding_percent(a percentage of the bounding box's diagonal - so it scales with the subject, which is a nicer default than you'd think). Context matters: models crop tight and tend to cut off edges, and the padding also gives the paste step room to blend. - Divisible-by centering. The crop is centered on the bbox and its width/height get snapped up to the nearest multiple of
divisible_by(2, 4, 8, 16, 32, or 64). This is the "clean tile size" feature - set 8 or 16 and every crop comes out at a multiple your model and tiling setup actually like. Flux wants multiples of 64 for full-frame work; 8 is the safe floor for most inpainting. - Resize. With
resize_enabledon (it's on by default), the longer side gets scaled tolonger_side(default 1024) using LANCZOS for the image and nearest-neighbor for the mask. That mask detail matters: nearest keeps the mask hard-edged instead of turning it into a fuzzy grey gradient that contaminates your inpaint.
The inputs that matter
You mostly touch a handful:
- mask - the region to crop around. Any MASK output works: a hand-painted mask, a SAM segment, a YOLO bbox mask, whatever.
- padding_mode + padding_pixels / padding_percent - how much context to add around the bbox. Start at 32–64px in pixels mode; the detailing community's standard padding advice applies here.
- longer_side - set it to your model's native resolution. 512 for SD1.5-era, 1024 for SDXL/Flux. This is the whole point: the crop gets its own generation budget at native res.
- divisible_by - clean tile sizes for tiling/upscale setups.
Outputs are cropped_image (IMAGE), cropped_mask (MASK), and pipe (PIPE). The pipe is the clever bit: it bundles the crop's coordinates, the original image, and the mask into one object, so CNP Paste can put everything back without you re-wiring coordinates. Feed the crop into your model of choice and keep the pipe handy.
Install
ComfyUI Manager → Install Custom Nodes → search "CNP Crop And Paste", or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/dapa5900/ComfyUI-CNP-CropAndPaste.git
Restart ComfyUI and it shows up under Crop And Paste. No models, no heavy deps - honestly, the cleanest install in the pack.
Where people get tripped up
An empty mask returns the whole image unchanged - the bbox check just bails and passes everything through, which can look like a silent no-op if your SAM node missed. The crop is always centered on the bbox and clamped to the canvas, so a mask near the image edge gives you an asymmetric crop; add padding on the other side to compensate. And note this is one bbox per image: the bounding box of the entire mask, not per-connected-component. For multiple separate objects you want the Impact Pack's SEGS machinery, not this. If you'd rather have the full-featured crop-inpaint-stitch experience, the community standard is lquesada's Inpaint CropAndStitch - CNP Crop is the lighter, no-config option when you want to control crop resolution yourself.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| padding_mode | COMBO | pixels | 2 options: pixels, percent |
| padding_pixels | INT | 00–1024 | — |
| padding_percent | INT | 00–100 | — |
| resize_enabled | BOOLEAN | true | — |
| longer_side | INT | 1024256–4096 | — |
| divisible_by | COMBO | 2 | 6 options: 2, 4, 8, 16, 32, 64 |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| cropped_image | IMAGE | — |
| cropped_mask | MASK | — |
| pipe | PIPE | — |