Nearest Divisible Int
Snap Any Resolution to a Multiple of 8 (or 16, or 64)
- result
Diffusion models are picky about dimensions. SD 1.5 wants multiples of 8, SDXL and a lot of modern models want multiples of 16 or 64, and video models like Wan get genuinely unhappy with off-grid resolutions. Nearest Divisible Int is the tiny node that fixes it: give it a number and a divisor, and it returns the nearest integer that divides evenly by that divisor. Chain two of them (one for width, one for height) and any arbitrary resolution gets snapped to a safe grid before it hits a sampler.
It's from artyclaw/artyclaw-comfy, and it's the kind of utility that earns its keep silently - you stop thinking about it the moment your "odd" resize results stop producing artifacts or VAE warnings.
How it works
Pure arithmetic, and the source is explicit about the tie-breaking rule. Given value and divisor:
lower= value rounded down to the nearest multiple.upper= lower + divisor.- If the value is closer to
upper, it rounds up; otherwise down. Ties go up - at exactly halfway, you get the higher multiple.
So 514 with divisor 16 → 512 (down), 520 with divisor 16 → 528 (up, since 520 − 512 = 8 ≥ 8, the half-way point). A divisor of 0 or negative is ignored and the value passes through unchanged, so a misconfigured graph fails safe instead of crashing.
Inputs and output
- value - the integer to adjust (default 512, max 999999).
- divisor - the grid you want (default 16, up to 1024). 8 for SD 1.5-era pipelines, 16 for most modern ones, 64 if you're being extra safe on a video model.
One output, result (INT). Typical wiring: put it between a "calculate resolution" node (or a free-text size) and a latent/Empty Latent Image's width input.
Install
ComfyUI Manager → search ArtyClaw Comfy Nodes, or:
cd ComfyUI/custom_nodes
git clone https://github.com/artyclaw/artyclaw-comfy
Restart. Standard library (math) only.
Where people get burned
The tie-goes-up rule surprises people who expect round-half-down - 512 with divisor 16 is already a multiple so it's a no-op, but 520 → 528 (not 512), which can be one step higher than you eyeballed. Second, it takes integers only: feed it a float and you'd better have a conversion node upstream, because this snaps whole numbers. Third, remember it rounds to the nearest multiple, not down - if you have a hard VRAM budget, you may want to round down instead, and this node won't do that for you. Small, predictable, and worth having in the toolbox precisely because it removes a whole class of "why is my output stretched/tiled" questions.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| value | INT | 5120–999999 | — |
| divisor | INT | 161–1024 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | INT | — |