AdjustRect
Snap a crop rectangle to latent-friendly multiples without moving its center
- INT
- INT
- INT
- INT
ComfyUI is picky about dimensions. Latents want multiples of 8, and a lot of inpainting and upscale setups are happiest when crop sizes land on 64. So when some other node hands you a bounding box that's 613×287 - fine for a computer-vision mask, useless for a sampler - you need AdjustRect. It takes a rectangle, keeps its center, and snaps its width and height up or down to multiples you choose.
The mental model is simple: think of it as a "round this rectangle to the grid" node. xm and ym are the grid steps (defaults 64, both), and the node returns a new rectangle with the same center but width a multiple of xm and height a multiple of ym. The classic use is between a detection step (face box, contour bounds, prompt-defined region) and a crop/inpaint step: snap first, crop on clean numbers, no "size must be divisible by 64" errors.
Inputs and outputs
a,b,c,d- the four numbers describing your rectangle.input_format/output_format- how those four numbers are interpreted and returned. The four choices: top-left XY + WH, top-left XY + bottom-right XY (the default), center XY (floored) + WH, and center XY + half WH (all floored). Set the input to match whatever node produced the rect, set the output to match whatever consumes it - this is the knob that makes the node talk to anything.xm,ym(default 64) - the multiples to snap to.round_mode- Floor (keep it tight), Ceil (need margin), Round (closest to original), or Exact (skip the multiple-snapping entirely and return the exact defined dimensions). Exact is your "please just convert formats" escape hatch.
Output is four INTs, in whatever output_format you chose, ready for a crop, an inpainting region, or the pack's own rectangle machinery.
Install
Part of bmad4ever/comfyui_bmad_nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
cd comfyui_bmad_nodes
pip install -r requirements.txt
Restart, or ComfyUI Manager → search comfyui_bmad_nodes. No model downloads; this node is pure math, though the pack as a whole pins opencv-python~=4.8.1.78 via its requirements.
Gotchas
The format conversion is where mistakes hide. The node converts your a,b,c,d from input_format to output_format - so if you tell it the numbers are "top-left XY + bottom-right XY" when they're actually "top-left XY + WH," every output is wrong, silently, and no error tells you. Also note the README's caveat: the returned corners can fall outside the image space, especially with Ceil or when the original box hugs an edge - a downstream crop may then complain. And when you genuinely don't need multiples (e.g. feeding a custom canvas), that's what Exact is for.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| a | INT | 0–2147483647 | — |
| b | INT | 0–2147483647 | — |
| c | INT | 0–2147483647 | — |
| d | INT | 0–2147483647 | — |
| xm | INT | 642–1280 | — |
| ym | INT | 642–1280 | — |
| round_mode | COMBO | Round | 4 options: Floor, Ceil, Round, Exact |
| input_format | COMBO | top-left XY + bottom-right XY | 4 options: top-left XY + WH, top-left XY + bottom-right XY, center XY (floored) + WH, center XY + half WH (all floored) |
| output_format | COMBO | top-left XY + bottom-right XY | 4 options: top-left XY + WH, top-left XY + bottom-right XY, center XY (floored) + WH, center XY + half WH (all floored) |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |
| INT | INT | — |
| INT | INT | — |
| INT | INT | — |