π Image Resize to Nearest Model Resolution
Your img2img is eating off-model resolutions. This node stops it.
- image
- IMAGE
- WIDTH
- HEIGHT
Every img2img workflow hides the same landmine: you load an image, resize it to whatever feels right, and only find out later that the resolution you picked isn't one the model was ever trained on. Diffusion models aren't resolution-agnostic. They're trained at specific ratios, and drifting off those produces stretched anatomy, doubled heads, and repeated textures. The standard fix - generate at a native resolution, upscale after - is well known. The resize before the latent encode step is the one people keep botching.
π Image Resize to Nearest Model Resolution exists to botch it for you. Pick which model you're about to feed, and it snaps your image to the closest resolution from that model's training table, so the VAE encodes a canvas the model actually speaks.
How it works
The clever part is that this isn't a generic "round to nearest multiple of 64" node - ComfyUI already has plenty of those. The author hardcoded the actual resolution tables each model was trained on: the full SDXL ratio list (704Γ1408 up to 1728Γ576), Flux's set, Wan 2.2's many buckets, LTXV, Qwen Image, Z-Image Turbo, ERNIE, Anima, Flux2, and Microsoft Lens. That's ten models' worth of real training resolutions baked into the source, not guessed.
To match your image to a table, it scores every candidate on two things: aspect-ratio proximity (weighted 2Γ so it never flips your orientation) and pixel-area proximity (the tiebreaker between same-ratio candidates). So a tall portrait in gets a tall portrait out, just at a resolution the model was trained on. It then resizes to the exact listed dimensions - which means the output aspect ratio can shift a little. That's deliberate: a valid training resolution beats a slightly nicer crop that the model chokes on.
The inputs that matter
- model - the resolution table to match against. If your model isn't in the list, this node isn't for you; pick the closest architecture or use a plain resize.
- interpolation_mode - bicubic, bilinear, lanczos, nearest, or nearest exact. If you're upscaling, lanczos gives the sharpest result; downscaling, bicubic is the usual recommendation and it's faster. Nearest modes are for pixel art where you don't want blending.
- resize_longest_side - default 0 means "use the model's native resolution exactly." Set it to cap the output's longest side - handy for VRAM budgeting.
One honest gotcha: the tooltip says this setting "scales the best-matching resolution proportionally," but the code actually treats it as a cap - it filters the table to resolutions whose longest side fits under your number and picks the best aspect match among those. Output is always a listed resolution, never an arbitrary scaled size. Trust the behavior, not the help text. It falls back to the smallest resolution if nothing fits your cap.
Outputs
You get three: the resized IMAGE, plus WIDTH and HEIGHT as separate integers. Wire those into an Empty Latent (or your latent-size-aware img2img chain) so the latent is sized to match the image exactly, and you sidestep the classic "image is 1372 wide but latent was built for 1344" mismatch.
Installation
Boring in the best way - no model downloads, no heavy dependencies, just torch/torchvision/PIL that ComfyUI already ships. Via Manager: search comfyui-image-resize-to-model-resolution (publisher river-side) and install. Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/RiverSide71/comfyui-image-resize-to-model-resolution
Then restart ComfyUI. You'll find it under the riversidenodes category.
Small-author reality check: this pack isn't a household name, the README is minimal, and the tooltip/behavior mismatch above shows it's a bit rough around the edges. But the mechanism is sound, and for img2img into SDXL, Flux, or Wan it does exactly one job well: the resize you keep doing by hand, now with a table instead of vibes.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | β | |
| model | COMBO | 10 options: Qwen_Image, Z_Image_Turbo, MiniMax_H3, SDXL, Flux, Flux2, +4 | |
| interpolation_mode | COMBO | 5 options: bicubic, bilinear, lanczos, nearest, nearest exact | |
| resize_longest_side | INT | 00β8192 | 0 = use the model's native resolution exactly. Any other value: the best-matching resolution is scaled proportionally so its longest side equals this number (rounded to the nearest 8 px). |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | β |
| WIDTH | INT | β |
| HEIGHT | INT | β |