Nodes/ComfyUI 1hewNodes/Image Crop With BBox Mask
ComfyUI Node

Image Crop With BBox Mask

Crop around your subject's mask — and remember where it came from

By 1hew·Created about a year ago·Updated 7 days ago· 33
Image Crop With BBox Mask
  • image
  • mask
  • get_crop_ratio
  • cropped_image
  • bbox_mask
  • cropped_mask
preset_ratiomask
scale_strength0.00
crop_to_sideNone
crop_to_length1024
divisible_by8

The "crop, process, paste back" loop is the backbone of inpainting and local upscaling: find the subject, crop tightly around it, run the expensive model on that crop, then put the result back where it came from. The crop part is easy. The putting it back part is where workflows die, because you need to remember the exact bounding box. Image Crop With BBox Mask solves both halves: it crops intelligently around your mask's bounding box, and it hands you back a bbox_mask that records the crop's position in the original image - the key to a clean paste-back.

This is a genuinely useful node for inpainting prep, face fixes, dataset building, and anything that needs "subject extracted at a known location."

How it works

The node takes the mask's bounding box, then shapes the crop around it:

  • preset_ratio - the target aspect ratio: mask (fits the subject's own bbox ratio closely), image (original image ratio), auto (snaps to the nearest standard ratio like 4:3 or 16:9), or an explicit ratio from the list. Default mask, which is right for most subjects.
  • get_crop_ratio - an optional reference image that overrides preset_ratio entirely: the crop matches this image's aspect. Handy when you want all crops to match a fixed canvas.
  • scale_strength - 0–1. Extends the crop box outward while keeping the ratio, pulling in more background context. 0 is a tight fit; higher values stop the subject from touching the crop edges.
  • crop_to_side + crop_to_length - physical output size control: fix the longest, shortest, width, or height to a length (e.g. long side = 1024).
  • divisible_by - rounds output dimensions to a multiple (default 8; 16 for some models), so the crop lands on model-friendly sizes.

Outputs are the trio that makes paste-back work:

  • cropped_image - the crop, resized to the final size.
  • bbox_mask - a mask in original image dimensions; white marks exactly where the crop happened. This is the "map" for restoring.
  • cropped_mask - your input mask cropped and resized to match cropped_image, for aligned downstream compositing.

Install

Part of ComfyUI-1hewNodes:

cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes

Restart ComfyUI. No models, no downloads.

Where it fits

The canonical loop: mask the subject (matting, or a SAM box) → crop here → inpaint or upscale the crop → paste back using bbox_mask - the pack's Image Paste by BBox Mask is built for exactly that handoff. Also solid for dataset prep: batch-crop subjects to a uniform 1024×1024 with crop_to_side + divisible_by.

Common issues

  • get_crop_ratio connected and nothing changed when you tweaked preset_ratio - by design, the reference image wins. Disconnect it to use the ratio presets.
  • Subject touches the edge - scale_strength is your knob; 0.1–0.2 usually adds enough breathing room.
  • Empty or invalid mask - the node returns default black/white outputs instead of crashing, so a dead branch won't kill the queue. Spot-check if you see a black crop.

If you've ever hand-jotted down crop coordinates to restore an image, this node is the version of that chore that never makes arithmetic mistakes.

Category1hewNodes/image/crop

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
maskMASK
preset_ratioCOMBOmask13 options: mask, image, auto, 9:16, 2:3, 3:4, +7
scale_strengthFLOAT0.000–1
crop_to_sideCOMBONone5 options: None, longest, shortest, width, height
crop_to_lengthINT10248–8192
divisible_byINT81–1024
get_crop_ratiooptIMAGE

Outputs (3)

NameTypeDescription
cropped_imageIMAGE
bbox_maskMASK
cropped_maskMASK