Nodes/Pond Nodes/🐳bbox裁剪
ComfyUI Node

🐳bbox裁剪

Undo the padding you did on the way in

By Pondowner857·Created about a year ago·Updated 28 days ago· 45
🐳bbox裁剪
  • image
  • bbox
  • cropped_image
  • crop_mask
  • crop_data
bbox_index-1
expand_top0
expand_bottom0
expand_left0
expand_right0
feather0

The "pad to 64" trick is great on the way into the sampler and annoying on the way out. You pad a latent up to a 64-multiple so SDXL doesn't squish your subject, sample happily, decode - and get a perfectly generated image wrapped in letterbox bars. Crop By BBox is the node that cuts those bars back off. It's the exact counterpart to Smart Latent's padding: Smart Latent emits a bbox_json describing where your real content lives inside the working canvas, and this node reads that JSON and crops the decoded image back to it.

Both live in the SDXL Adherence pack (regiellis/ComfyUI-SDXL-Adherence), and honestly, if you're using Smart Latent in pad_up mode you should consider Crop By BBox a mandatory second half of the deal. Without it you're shipping padded images.

How it works

The bbox_json format is {x, y, w, h, W, H} - x/y/w/h is the original content region, W/H is the full working (padded) canvas. The node first maps that region from working-space into whatever size the image actually is right now (it scales by ratio, so it still works if the image changed size between decode and crop), then crops. A few refinements:

  • resize_back (default on) - after cropping, resizes back to the original content size w×h. Off if you want the crop at current resolution.
  • clamp_to_bounds (default on) - keeps the crop rect inside the image so you don't read out of bounds.
  • feather - softens the crop edge (0–32 px), useful if you're compositing the crop onto something instead of saving it flat.
  • expand - grows the crop rect by N pixels in all directions, if you want a margin of padded context back.

Inputs and outputs

Two required: image (the decoded image, H×W×C or batched) and bbox_json (the STRING from Smart Latent or Align Hints To Latent - wire those straight in). Outputs are image_cropped, which is your final deliverable, and info_json, a STRING with the mapped coordinates and a resized_to_original flag. If you're wondering whether the crop is doing what you think, info_json is the place to look.

Installing it

One pack, one install:

cd ComfyUI/custom_nodes
git clone https://github.com/regiellis/ComfyUI-SDXL-Adherence

Restart ComfyUI, or search "SDXL Adherence" in ComfyUI Manager. No models, no extra dependencies.

Where people get burned

  • Wrong bbox. If you feed it a bbox from a different latent than the one you actually decoded, the crop will be off. Keep the bbox_json flowing in a straight line from the Smart Latent that made the latent to the Crop By BBox that decodes it.
  • Invalid JSON. The node doesn't crash - it passes the image through untouched and puts a warning in info_json. If you get a crop that's mysteriously just your padded image, that's what happened.
  • Feather is for compositing. With feather > 0 the edges fade to transparent-ish, which looks broken if you just save the image. Leave it at 0 for a plain crop.

Small node, small job, and it does it without needing a single parameter invented by you. That's the whole point of the bbox round-trip.

Category🐳Pond/bbox

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
bboxBBOX_LIST
bbox_indexINT-1-1–99
expand_topINT0-9999–9999
expand_bottomINT0-9999–9999
expand_leftINT0-9999–9999
expand_rightINT0-9999–9999
featherINT00–9999

Outputs (3)

NameTypeDescription
cropped_imageIMAGE
crop_maskMASK
crop_dataCROP_DATA