Nodes/ComfyUI-Studio-nodes/🧩 Aspect Ratio Image Size
ComfyUI Node

🧩 Aspect Ratio Image Size

The resolution calculator that thinks in model-native sizes

By comfyuistudioΒ·Created about a year agoΒ·Updated 5 months agoΒ· 4
🧩 Aspect Ratio Image Size
    • width
    • height
    • resolution_label
    β—„width0β–Ί
    β—„height0β–Ί
    β—„aspect_ratio1:1β–Ί
    β—„directionHorizontalβ–Ί

    Every model was trained at a native resolution, and its training data came in specific aspect ratios. SDXL is happiest at 1024Γ—1024 or its rotated ratios like 1216Γ—832 and 1344Γ—768; generate way off those and you get doubled anatomy or stretched bodies. The annoying part is doing that math by hand every time you swap from landscape to portrait. AspectRatioImageSize is a tiny calculator that does it for you, and it has a nice default trick: leave both dimensions at zero and it just gives you a sensible ~1-megapixel size in your chosen ratio.

    It's a pure number node - no image goes in. You get three outputs: width (INT) and height (INT), which you wire straight into an Empty Latent Image, plus resolution_label, a "1920Γ—1080"-style string you can feed to a text display if you want the workflow to tell you what it's about to render.

    How the math works

    The node follows a simple priority order, which is worth knowing because it explains some surprising results:

    • Both width and height set (> 0): it trusts you completely and returns exactly what you typed. The aspect ratio setting is ignored.
    • Only width set: it derives the height from the ratio. 1920 Γ— 16:9 β†’ 1920Γ—1080.
    • Only height set: it derives the width.
    • Both zero: it targets one megapixel (1,000,000 pixels) and solves width = sqrt(1,000,000 Γ— w/h), then rounds both to the nearest multiple of 16. That's the "auto" mode and it's the one you'll reach for most: 16:9 β†’ 1328Γ—752, 1:1 β†’ 992Γ—992, 21:9 β†’ 1536Γ—656.

    direction flips the ratio for you, so "16:9 Vertical" gives 752Γ—1328 instead of having to reason through the inverse ratio yourself. The ratio list is fixed to ten presets (1:1, 16:9, 5:4, 4:3, 3:2, 2.39:1, 21:9, 18:9, 17:9, 1.85:1) - there's no free-text box, so if you need something exotic like 4:5, you're either picking the nearest preset and swapping direction, or just setting one dimension by hand and letting the node derive the other.

    The gotcha nobody mentions

    The 1MP path rounds to multiples of 16 (good, latents love that). But the width-only and height-only paths don't round at all. So 1920 Γ— 16:9 gives you 1920Γ—1080, and 1080 is not divisible by 16. Most modern models shrug at that, but some VAE/upscale pipelines will complain or tile oddly on non-16-aligned latents. If you're feeding this into a latent, either set both dimensions to pre-rounded values or keep the width-only trick to rough sizes you can afford to fudge. It's a small wart on an otherwise handy node.

    Install

    The pack's README is thin and never says how to install it, so do the standard thing:

    cd ComfyUI/custom_nodes
    git clone https://github.com/comfyuistudio/ComfyUI-Studio-nodes
    

    Then restart ComfyUI. Dependencies are just numpy, torch and Pillow - all things ComfyUI already ships - so there's nothing extra to pip install. ComfyUI Manager users: the pack isn't reliably in Manager's catalog search, so paste the git URL into Manager's "install from git URL" field if you'd rather stay click-driven.

    The node lives under the "STUDIO NODES" category, alongside its sibling AspectRatioResizeImage which does the actual resizing of pixels rather than just the math. If you're prepping dimensions for generation, you want this one; if you're squashing an existing image into a ratio, you want the other.

    One honest caveat: this is a 4-star, single-commit pack, so don't expect updates or a changelog. The math here is simple enough that "review the source before you trust it" applies to the whole pack - read the aspectratio.py file once and you'll know exactly what you're getting.

    CategorySTUDIO_NODES

    Inputs (4)

    NameTypeDefaultDescription
    widthINT00–4096β€”
    heightINT00–4096β€”
    aspect_ratioCOMBO1:110 options: 1:1, 16:9, 5:4, 4:3, 3:2, 2.39:1, +4
    directionCOMBOHorizontal2 options: Horizontal, Vertical

    Outputs (3)

    NameTypeDescription
    widthINTβ€”
    heightINTβ€”
    resolution_labelSTRINGβ€”