Image Crop By Mask Resolution Grp JK๐
Image Crop By Mask Resolution Grp JK does the geometry
- mask
- image
- latent
- crop_width
- crop_height
- offset_x
- offset_y
- target_width
- target_height
The crop-by-mask pipeline needs one thing before anything else: geometry. What rectangle does this mask bound, and what resolution should that rectangle become? Image Crop By Mask Resolution Grp JK is the node that computes it - you feed a mask, it finds the mask's bounding box, applies your padding and resolution strategy, and hands back crop_width, crop_height, offset_x, offset_y, target_width, and target_height. Six integers that another node (or your own crop logic) can act on directly.
The mechanism, step by step:
- Bounding box - it scans the mask for non-zero pixels and finds the tight rectangle around them. An empty mask (all zeros) returns the full image area, so an unselected region degrades to "crop everything" rather than crashing.
- Padding - expands the box by
paddingpixels, clamped to the image edges. - Resolution strategy - exactly one of three flags should be on:
use_image_res(base the target on the source image's own resolution),use_target_res(use the fixedtarget_resvalue), oruse_target_mega_pixel(scale so the crop lands near the given megapixel count). With none on, it just uses the padded crop's longest side. - Multiple-of-8 rounding - the final
target_width/target_heightsnap to multiples of 8 and preserve the crop's aspect ratio. That 8-alignment is non-negotiable for latent operations - VAEs and samplers expect it, and this node handles it so you don't have to.
Optional image or latent inputs provide the source dimensions (latent gets the ร8 conversion); with neither, it assumes 1024ร1024.
The "Grp" in the name: this node was built to serve Jake's group nodes and subgraphs - the "Image Crop by Mask" tool groups use these exact outputs to slice, resize, and stitch back. You'll rarely wire it by hand unless you're building a custom crop loop, but when you do, remember the golden rule of crop/stitch: the crop and the stitch must use the same geometry. Save offset_x/offset_y and crop_width/crop_height from here and feed them to both the crop and the paste-back, or your image will drift.
Install. It's part of ComfyUI-JakeUpgrade:
cd ComfyUI/custom_nodes
git clone https://github.com/jakechai/ComfyUI-JakeUpgrade
cd ComfyUI-JakeUpgrade
pip install -r requirements.txt
Or ComfyUI Manager โ "JakeUpgrade". Windows portable: install.bat or ../../../python_embeded/python.exe -s -m pip install -r requirements.txt. Restart.
Gotchas: enabling two resolution flags at once isn't validated here (resolution beats megapixel in the pack's groups - keep one on). And while this node is pure math, its sibling Image Crop by Mask Params JK is pure parameter routing - if you need the inpaint_crop_and_stitch toggle as a wire, that's the other node. Pack rules: LOAD_DEPRECATED_NODES = True if JK nodes report missing, disable ComfyUI MultiGPU per the README.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | โ | |
| padding | INT | 00โ512 | โ |
| use_image_res | BOOLEAN | false | โ |
| use_target_res | BOOLEAN | false | โ |
| target_res | INT | 10240โ16384 | โ |
| use_target_mega_pixel | BOOLEAN | false | โ |
| target_mega_pixel | FLOAT | 1.000.01โ16 | โ |
| imageopt | IMAGE | โ | |
| latentopt | LATENT | โ |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| crop_width | INT | โ |
| crop_height | INT | โ |
| offset_x | INT | โ |
| offset_y | INT | โ |
| target_width | INT | โ |
| target_height | INT | โ |