ComfyUI Node
BD Crop and Center
Crop an image to the bounding box of its mask (like AILab Crop-to-Object), with optional centering. Bbox comes from the wired mask, else the image's alpha (RGBA) or its difference from the border background colour. canvas_width = canvas_height = 0 → output the TIGHT CROP (just the bbox region). canvas_width / canvas_height > 0 → place the crop on that canvas at the anchor (center / edges / corners), with optional scale_to_fit — this is the centering option. flatten_to_mask makes content show only inside the mask (background fills the rest of the crop). Outputs the cropped image, its mask, and a transform JSON.
BD Crop and Center
- image
- mask
- image
- mask
- transform
◄anchorcenter►
◄canvas_width0►
◄canvas_height0►
◄pad0►
◄threshold0.02►
◄scale_to_fitfalse►
◄background_hex#000000►
◄flatten_to_masktrue►
Category🧠BrainDead/Segmentation
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| maskopt | MASK | Mask defining the crop region (its bounding box). If absent, the bbox is taken from the image's alpha (RGBA) or its difference from the border bg. | |
| anchoropt | COMBO | center | Placement on the canvas (only used when canvas_width/height > 0). center = shared pivot; top/bottom/left/right + corners anchor by that edge. |
| canvas_widthopt | INT | 00–8192 | 0 = output the TIGHT CROP (no canvas). >0 = place the crop on a canvas this wide at the anchor. (If only one of width/height is >0, the other uses the input size.) |
| canvas_heightopt | INT | 00–8192 | 0 = tight crop (no canvas). >0 = canvas height for centering. |
| padopt | INT | 00–1024 | Pixels of margin added around the mask bbox before cropping (AILab-style padding). |
| thresholdopt | FLOAT | 0.020–1 | Mask/alpha value above which a pixel counts as content (for the bbox). |
| scale_to_fitopt | BOOLEAN | false | Canvas mode only. On = scale the crop to FIT the canvas (longest side → canvas), preserving aspect (up or down), then anchor. Off = keep original pixel scale (re-pivot only). |
| background_hexopt | STRING | #000000 | Background fill for masked-out / padded regions. |
| flatten_to_maskopt | BOOLEAN | true | On = content shows only inside the mask; the background colour fills the rest of the crop (and alpha = mask for RGBA). Off = output the raw rectangular crop (exactly like AILab Crop-to-Object). |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| transform | STRING | — |