Nodes/ComfyUI-PepeUtils/Stride Scale Size
ComfyUI Node

Stride Scale Size

The tiny math node that keeps your resolutions divisible

By Pepehoschi·Created 5 months ago·Updated 12 days ago· 0
Stride Scale Size
    • scaled_width
    • scaled_height
    • chosen_side
    image_width1024
    image_height1024
    rescale_by1.00
    stride8
    modedown
    side_selectorlongest
    clamp_rescale_min_1true

    Some nodes earn their keep by being complicated. Stride Scale Size earns its keep by being a calculator. It takes a width and height, scales them by a factor, snaps the result to a stride, and hands back the numbers - no image tensor in, no image tensor out. It's a utils/math node that does one job and does it without fuss.

    Why would you want that? Because ComfyUI quietly cares about divisibility. Latents and VAE decode behave better when your dimensions are multiples of 8 (or 16, or 64, depending on what you're feeding), and any resize or crop can leave you with a 1027×769 that should really be 1024×768. Instead of doing the mental arithmetic or stacking math nodes, you wire this in and the numbers come out already snapped.

    How it works

    The logic is short enough to read in one sitting. It multiplies image_width and image_height by rescale_by, then snaps each to the nearest multiple of stride using the mode you picked: down floors to the stride (so 1027 → 1024 with stride 8), up ceils (1030 → 1032), nearest rounds. It also computes chosen_side, which is just the shorter or longer of the two scaled dimensions depending on side_selector (shortest/longest).

    One subtlety worth knowing: the rescale_by widget has a minimum of 1.0, so the stock widget only scales up. The clamp_rescale_min_1 flag (on by default) enforces that too - it pins any factor below 1.0 up to 1.0. If you ever want sub-1 downscaling through this node, you'd feed a smaller value in from another node and turn that clamp off. In practice, upscaling-then-snapping is what the node is for.

    Inputs and outputs

    The inputs are all numbers: image_width, image_height, rescale_by, stride (default 8), mode (down/up/nearest), side_selector, and clamp_rescale_min_1.

    Outputs:

    • scaled_width, scaled_height - the snapped dimensions, ready to feed into an Empty Latent Image, a KSampler resolution, or a resize node's width/height.
    • chosen_side - whichever side you asked for. Useful when the workflow cares about "longest side ≈ 2048" rather than exact dimensions, which is how a lot of img2img and upscale setups reason.

    Installing it

    Stride Scale Size ships in Pepehoschi/ComfyUI-PepeUtils (GPL-3.0). Install via ComfyUI Manager (search "ComfyUI-PepeUtils") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Pepehoschi/ComfyUI-PepeUtils
    

    Restart ComfyUI. No extra dependencies - it's pure Python math on top of the standard ComfyUI stack.

    The honest take

    There's nothing glamorous here, and that's the point. You'll use it as glue: after a resize node where you want the output locked to 8-aligned dimensions, or before an Empty Latent Image when you want a "scale the source by 1.5, snap it, feed it to the sampler" chain that stays reproducible. It's the kind of node you forget you installed until a workflow needs clean divisible sizes - and then it's exactly the one you reach for instead of doing the math by hand for the hundredth time.

    Categoryutils/math

    Inputs (7)

    NameTypeDefaultDescription
    image_widthINT1024
    image_heightINT1024
    rescale_byFLOAT1.00
    strideINT8
    modeCOMBOdown3 options: down, up, nearest
    side_selectorCOMBOlongest2 options: shortest, longest
    clamp_rescale_min_1BOOLEANtrue

    Outputs (3)

    NameTypeDescription
    scaled_widthINT
    scaled_heightINT
    chosen_sideINT