Nodes/comfyui_imgtools/Image Dimension Fitter (rholdorf)
ComfyUI Node

Image Dimension Fitter (rholdorf)

Snap any size to the resolution your model actually wants

By rholdorf·Created 8 months ago·Updated 2 days ago· 0
Image Dimension Fitter (rholdorf)
    • target_width
    • target_height
    width1024
    height1024
    model

    "Generate at native resolution" is advice you hear constantly and obey rarely, because it means doing math. Your model has a small set of resolutions it was actually trained at - SD 1.5 around 262k pixels in multiples of 8, Flux and Z-Turbo around 1MP in multiples of 32 - and generating far off that grid costs you quality. This node takes a reference width and height and returns the closest standard resolution for whichever model family you're targeting, matched by aspect ratio. That's the whole job, and it does it more consistently than you will by eye.

    How it works

    Feed in width, height, and a model (SD, Flux, Z-Turbo, or Krea 2). The node computes your aspect ratio and finds the closest entry in that model's resolution table by ratio distance; ties resolve to the smaller-total-pixel candidate, so it never hands you a resolution bigger than you need. The tables live in the source and are worth knowing:

    • SD - 512x512 up through 768x512 / 512x768: about 262k pixels, all divisible by 8.
    • Flux - 1024x1024, 1152x896, 1216x832, 1344x768, 1536x640, 1920x1080 plus portrait mirrors: about 1MP, all divisible by 32.
    • Z-Turbo - the same list as Flux minus the 16:9 1920x1080 pair.
    • Krea 2 - derived from Krea's published aspect ratios targeted at ~1MP, each side floored to a multiple of 32. Approximate by design, because Krea doesn't publish exact pixel dimensions; it biases downward, which is the right failure direction.

    Inputs and outputs

    Inputs: width, height (reference dimensions, default 1024 - the tooltips call them "used to detect the closest model resolution"), and the model dropdown. Outputs: target_width and target_height as INTs.

    In a workflow

    The classic wiring: take the size of an actual image - say, from the pack's Image Resize (Lanczos 3 non-separable) width/height outputs, or the size of a reference latent - run it through here with the model set to what you're actually sampling, and connect the result to Empty Latent Image. One workflow, and you can flip the model in the dropdown and every canvas updates to the right grid. It's also a sanity node for img2img: size your input to the fitter's output and you're sampling at a size the model knows rather than a size it tolerates.

    One caveat if you've seen this node described elsewhere: older writeups describe a version that takes an image and center-crops it to target dimensions. The current build is the dimension-snapper above - width/height/model in, two INTs out. If a saved workflow of yours has an image input wired into it, that workflow is stale; update the pack.

    Install

    Part of the small comfyui_imgtools pack by rholdorf. Install once, get all 11 nodes:

    cd ComfyUI/custom_nodes
    git clone https://github.com/rholdorf/comfyui_imgtools
    

    Restart ComfyUI. Or search "rholdorf" in ComfyUI Manager. No build step, no extra dependencies - it's pure Python on the torch/numpy/Pillow ComfyUI already ships. Young, low-star solo pack: MIT, short readable code, no network calls, no model downloads. JS changes under web/ need only a browser refresh; Python changes need a restart.

    Categoryrholdorf/image

    Inputs (3)

    NameTypeDefaultDescription
    widthINT10241–16384Reference width — used to detect the closest model resolution.
    heightINT10241–16384Reference height — used to detect the closest model resolution.
    modelCOMBO4 options: SD, Flux, Z-Turbo, Krea 2

    Outputs (2)

    NameTypeDescription
    target_widthINT
    target_heightINT