Extensions/Resize to Multiple
ComfyUI Extension

Resize to Multiple

Resize an image to the closest standard aspect ratio at a target megapixel count, snapped to a selectable pixel multiple, with image, VAE latent, empty latent (SDXL / Flux.2 Klein) and width/height outputs.

By speedyrulz·Created about a month ago·Updated about a month ago· 1
speedyrulz/ComfyUI-resize-to-multiple
Nodes—
On cloudLocal install
Stars1
Updatedabout a month ago
Readme

ComfyUI Resize to Multiple

A ComfyUI custom node that resizes an image to the closest standard aspect ratio at a target megapixel count, with every edge snapped down to a selectable pixel multiple — ready for SDXL and Flux.2 Klein sampling.

What it does

  1. Matches the aspect ratio. The input image is compared against 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 16:9, 9:16 and the closest ratio wins (log-space distance, so e.g. 3:2 and 2:3 are treated symmetrically).
  2. Resizes with Lanczos to that ratio at the selected megapixel target (0.1–4.0 MP dropdown). The resize uses a center-crop fit, so the image is never stretched or squashed.
  3. Snaps to a multiple. Each edge is rounded down to the nearest multiple of the selected value (2, 4, 8, 16, 32 or 64; left unchanged if it already is one), and the image is center-cropped to those exact dimensions. Use 16 for Flux.2; SDXL needs at least 8.
  4. Shows the resolutions. After each run the node displays the input and output resolutions plus the matched ratio directly on the node, e.g. 3000×2000 → 1224×816 / 3:2 · 1.00 MP.
  5. Custom resolution override. Enable use_custom_resolution to ignore the megapixel target and aspect matching entirely: the image is resized and center-cropped to custom_width × custom_height, with each edge rounded down to the selected multiple.

Outputs

| Output | Type | Description | |---|---|---| | image | IMAGE | The resized image. | | latent | LATENT | The resized image encoded with the (optional) vae input. | | empty_latent | LATENT | An empty latent at the final resolution, in the format chosen by the empty_latent_type dropdown. | | width | INT | Final image width in pixels. | | height | INT | Final image height in pixels. |

The outputs can be used individually or together:

  • Only using image, empty_latent, width or height? Leave the vae input unconnected.
  • Using latent? Connect a VAE. If a downstream node tries to consume the latent output while no VAE is connected, it is blocked with a clear error message instead of receiving garbage.

Empty latent formats

| Choice | Channels | Downscale | Works with | |---|---|---|---| | SDXL (and compatible) | 4 | 8× | SD1.5, SD2.x, SDXL, and other 4-channel models | | Flux.2 Klein (and compatible) | 128 | 16× | Flux.2 Klein, Flux.2 dev |

Installation

Clone (or copy) this folder into ComfyUI/custom_nodes/ and restart ComfyUI:

ComfyUI/custom_nodes/ComfyUI-resize-to-multiple/

The node appears as Resize to Multiple under image/transform.

Notes

  • The final resolution is always ≤ the selected megapixel target, because every step rounds down (e.g. 1.0 MP at 1:1 with multiple 16 → 992×992).
  • With multiples smaller than the latent downscale (8 for SDXL, 16 for Flux.2), the latents cover the image floor-cropped to the latent grid — the same behavior as ComfyUI's own VAE Encode on odd-sized images.
  • Batched images are supported; the latents match the input batch size.