Align Resolution to Grid
The node that kills ComfyUI's bottom-edge garbage band (1920×1080 → 1088)
- width
- height
- changed
- label
Ever rendered a Krea 2 image at 1920×1080 and noticed a weird 8-pixel strip of smeared junk along the bottom edge that you don't remember generating? That's not your prompt. That's a resolution alignment bug, and Align Resolution to Grid exists to stop it before it happens.
Here's the deal. Modern latent-space models don't think in pixels. A Krea 2, Flux, or SD3 image goes pixels → VAE downscale → DiT patch tokens, and every dimension has to be a multiple of vae_downscale × patch_size - 16 for Krea 2, Flux, SD3, Qwen-Image and Wan, 32 for MiniMax H3, 64 if you're still on SDXL/SD1.5. 1080 is a multiple of 8 but not 16, so when ComfyUI hits a lazy dimension it runs pad_to_patch_size and pads the latent up with circular padding: the pad row is a wrapped copy of the top of the image, folded into the same patch token as your real bottom row, and the model decodes that never-seen-in-training combo into a garbage band. Always bottom/right, never top/left, because padding is only ever appended. 1920×1080 bands on Krea 2 (1080/8 = 135 latent rows, odd). 1920×1088 doesn't (136, even). That's the whole bug in two sentences.
What makes it sneaky: ComfyUI's built-in Resolution Selector defaults its multiple to 8, which is exactly the value that walks you into the band. This node is from the same pack as Resolution Preset and Resolution Selector (Real MP), but where those pick resolutions you choose, this one snaps dimensions you didn't choose - an img2img source, a ControlNet reference, or an upscale chain where multiplying by 1.5 landed you at 1620×1136 or whatever off-grid nonsense.
The inputs, which is basically all of them
- width / height (defaults 1920×1080) - whatever size landed on your desk.
- alignment (default 16) - the grid both axes must hit. The author's own tooltip is the cheat sheet: 16 for Krea 2 / Flux / SD3 / Qwen-Image / Wan, 32 for MiniMax H3, 64 for SDXL / SD1.5. One genuinely useful simplification: just set 32 for everything. It's a multiple of 16, so every size it produces is legal on both Krea 2 and H3, and you stop tracking which model needs which grid.
- mode (
round/up/down) -roundis the default and fine most of the time. Useupwhen you must never shrink (you'll add a few pixels of canvas rather than lose framing) anddownwhen you have a hard pixel budget.
The outputs are width, height, and two freebies: changed (true if anything was off-grid - wire it somewhere if you want to conditionally react, or just ignore it) and label, a "1920x1088" string that's handy for a filename_prefix.
How to install it
Nothing heavy here - it's pure stdlib math, no dependencies, no model downloads. ComfyUI Manager, search "ComfyUI-ResolutionTools", or:
cd ComfyUI/custom_nodes
git clone https://github.com/dreevelle/ComfyUI-ResolutionTools
Then restart ComfyUI. Wire the width/height outputs into an Empty Latent node's width/height inputs (or straight into whatever node takes dimensions) and you're done.
Where people get burned
The most common trap is feeding 1920×1080 straight into Krea 2 because "1080 is divisible by something, right?" and then cropping the band out in post, losing real pixels. The fix is to generate at 2048×1152 instead - it's exactly on-ratio and on-grid, then downscale once at the end with a lanczos Upscale Image at 1920×1080 (not Upscale Image By, which rounds its scale factor and lands you back on an off-grid size). And if you're on MiniMax H3, remember the grid is 32, not 16 - that's the difference between a clean render and a 16-pixel band you'll spend an hour blaming on the sampler.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| width | INT | 19201–16384 | — |
| height | INT | 10801–16384 | — |
| alignment | INT | 161–256 | Pixel grid both axes must land on = VAE spatial downscale x DiT patch size. 16: Krea 2 / Flux / SD3 / Qwen-Image / Wan. 32: MiniMax H3. 64: SDXL / SD1.5, and universally safe. Getting this wrong causes a band of artifacts along the bottom/right edge. |
| mode | COMBO | round | round: nearest multiple. up: never shrink (may add letterbox). down: never grow (may crop framing). |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |
| changed | BOOLEAN | True if either dimension was off the grid. |
| label | STRING | — |