Nodes/comfyui_reimgsize/Resizebyratio
ComfyUI Node

Resizebyratio

The canvas calculator that stops you stretching your subjects

By MakkiShizu·Created 2 years ago·Updated about a year ago· 4
Resizebyratio
    • width
    • height
    size1024
    width_ratio1.000
    height_ratio1.000
    GCD64

    The name sets you up for disappointment. Resizebyratio doesn't resize anything - no image goes in, no image comes out. It's a calculator, and once you stop expecting pixels you'll find it genuinely handy: feed it three numbers and it hands back a width and height that fit both your resolution budget and your aspect ratio. That's the boring 90% of canvas math, done in one node instead of a notepad and a calculator.

    Here's why that's worth having. Every model has a native resolution and a set of aspect ratios it was trained on - SDXL wants roughly 1024 on the diagonal at specific trained ratios, Flux wants dimensions divisible by 64, Z-Image is happiest in a 1–2 megapixel band. The community's stock complaint about stretched bodies is almost always someone generating at an off-model ratio. So before you hit Empty Latent Image, you usually want dimensions that are (a) the right shape and (b) a sane total pixel count. That's exactly the pair Resizebyratio computes.

    How it works

    The whole node is three lines of math, which is the point of this pack: it's a "repetitive wheel" the author wrote for themselves, MIT-licensed and open, so the logic is right there to read. It computes:

    target  = size²
    ratio   = width_ratio / height_ratio
    height  = sqrt(target / ratio)
    width   = ratio * height
    width, height = rounded to nearest multiple of GCD
    

    Worked example: size = 1024, width_ratio = 16, height_ratio = 9 gives 1365×768, snapped to 1344×768. That's a 16:9 canvas at just over a megapixel, divisible by 64 - generate at that and Flux won't complain.

    The inputs that matter

    • size - your total-pixel budget, expressed as the side of a square. 1024 means ~1MP total, not "1024 wide." That's the mental model shift: this node thinks in area, not dimensions.
    • width_ratio / height_ratio - the aspect you want, as a pair. 16 and 9 for 16:9, 1 and 1 for square. If you only set one side of the pair you've effectively asked for that fraction.
    • GCD - the multiple everything snaps to. Default 64 matches Flux's divisibility requirement. Set it to 1 and snapping disappears.

    Outputs and where they go

    Two INTs, width and height. Wire them into an Empty Latent Image node's width/height for a "generate at ~1MP in 16:9" flow, or into Reimgsize's optional width/height ports (same pack) to force exact dimensions on a real image while it handles the upscaling.

    Install

    Same install for the whole pack, and there's nothing to it: the pack has zero Python dependencies beyond core ComfyUI and no model downloads. In ComfyUI Manager, search "comfyui_reimgsize" and install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MakkiShizu/comfyui_reimgsize.git
    

    Then restart ComfyUI. The nodes appear under the comfyui_reimgsize category.

    Gotchas

    Expecting it to resize an image is the big one - it won't, it's Resizebyratio, not "Resizebypixels." Also remember GCD rounding shifts the real total a few percent off your exact size²; that's usually fine, and honestly it's the point. If you just want a plain image resize at an arbitrary size, core ComfyUI's ImageScale does that already - this node is specifically for when you want your canvas sized the way the model likes it.

    Categorycomfyui_reimgsize

    Inputs (4)

    NameTypeDefaultDescription
    sizeINT102432–8192
    width_ratioFLOAT1.0000.001–64
    height_ratioFLOAT1.0000.001–64
    GCDINT641–512

    Outputs (2)

    NameTypeDescription
    widthINT
    heightINT