Nodes/ComfyUI-JakeUpgrade/Image Crop By Mask Resolution Grp JK๐Ÿ‰
ComfyUI Node

Image Crop By Mask Resolution Grp JK๐Ÿ‰

Image Crop By Mask Resolution Grp JK does the geometry

By jakechaiยทCreated 2 years agoยทUpdated 3 months agoยท 147
Image Crop By Mask Resolution Grp JK๐Ÿ‰
  • mask
  • image
  • latent
  • crop_width
  • crop_height
  • offset_x
  • offset_y
  • target_width
  • target_height
โ—„padding0โ–บ
โ—„use_image_resfalseโ–บ
โ—„use_target_resfalseโ–บ
โ—„target_res1024โ–บ
โ—„use_target_mega_pixelfalseโ–บ
โ—„target_mega_pixel1.00โ–บ

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:

  1. 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.
  2. Padding - expands the box by padding pixels, clamped to the image edges.
  3. 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 fixed target_res value), or use_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.
  4. Multiple-of-8 rounding - the final target_width/target_height snap 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.

Category๐Ÿ‰ JK/๐Ÿ›ฉ๏ธ Image

Inputs (9)

NameTypeDefaultDescription
maskMASKโ€”
paddingINT00โ€“512โ€”
use_image_resBOOLEANfalseโ€”
use_target_resBOOLEANfalseโ€”
target_resINT10240โ€“16384โ€”
use_target_mega_pixelBOOLEANfalseโ€”
target_mega_pixelFLOAT1.000.01โ€“16โ€”
imageoptIMAGEโ€”
latentoptLATENTโ€”

Outputs (6)

NameTypeDescription
crop_widthINTโ€”
crop_heightINTโ€”
offset_xINTโ€”
offset_yINTโ€”
target_widthINTโ€”
target_heightINTโ€”