Image_mask_crop_visual
Crop tight around a mask, at an exact size, with a way back
- image
- mask
- mask_stack
- crop_image
- crop_mask
- stitch
This is Apt_Preset's take on the crop-and-stitch pattern that took over masked image editing in 2026: crop tight around the region you actually care about, run your generation or edit at a controlled size, then paste the result back into the full image with everything outside that region left genuinely untouched. What sets this node apart from the plain Image_crop_visual is that the crop is driven by a mask, not just eyeballed.
How it works
Per the node's own description, the red box you see on the node represents aspect ratio and position only - not literal pixel dimensions. The actual output is always exactly crop_width × crop_height, regardless of how big the box looks on screen. The mask's minimum bounding rectangle has to be fully enclosed by that red box - the tool won't let you crop tighter than your masked region - and the box's aspect ratio is permanently locked to crop_width:crop_height, so you can't distort what you're cropping by dragging the box into some other shape.
The inputs and outputs that matter
image,mask(both required).crop_width/crop_height(default 512 each) - the real output size.crop_img_bj(default"image") - background fill if the crop box extends past the image edge (image/white/black/red/green/blue/yellow/cyan/magenta/gray).crop_state- the same drag/zoom-driven position JSON asImage_crop_visual.mask_stack(optional, typeMASK_STACK2) - Apt_Preset's own multi-mask type, for when one mask isn't enough control.- Output:
crop_image,crop_mask, and - the one to keep alive -stitch(typeSTITCH2), a token that remembers exactly where this crop came from so a matching restore step can paste the result back.
How to install it
Via ComfyUI Manager: search ComfyUI-Apt_Preset, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
Windows: install.bat. Linux/Mac: pip install -r ComfyUI-Apt_Preset/requirements.txt in your venv. Restart. Nothing to download for a crop tool - heavier dependencies in requirements.txt belong to other parts of this ~300-star, actively maintained pack.
Common issues & troubleshooting
The tool won't let you shrink the box as far as you want. That's the "must fully enclose the mask's bounding rect" rule doing its job - shrink your mask first if you genuinely want a tighter crop than the current mask allows.
Lost the ability to restore full frame afterward. Keep the stitch output connected all the way to whatever consumes it. Losing that connection anywhere in the middle means there's no path back to the full-frame image, and you'd have to composite the result back in manually.
Crop looks distorted relative to the mask. Remember the red box's on-screen shape is only aspect-ratio-and-position - actual output dimensions come from crop_width/crop_height alone. If the crop doesn't look like what the box implied, check those two numeric fields rather than the box itself.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| crop_width | INT | 5121–8192 | — |
| crop_height | INT | 5121–8192 | — |
| crop_img_bj | COMBO | image | 10 options: image, white, black, red, green, blue, +4 |
| crop_state | STRING | {"cx":0.5,"cy":0.5,"zoom":1.0} | — |
| crop_byScale | BOOLEAN | true | — |
| mask_stackopt | MASK_STACK2 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| crop_image | IMAGE | — |
| crop_mask | MASK | — |
| stitch | STITCH2 | — |