ComfyUI Node

Aspect Ratios

A blank latent that actually respects your aspect ratio

By jupo-ai·Created about a year ago·Updated 4 months ago· 2
Aspect Ratios
    • latent
    • width
    • height
    base1024
    fixed_side
    step8
    aspect_w1
    aspect_h1
    preset
    batch_size1

    The name is a lie in the best way: this node calls no API, needs no key, and downloads no models. It's a smarter replacement for the built-in Empty Latent Image - you give it an aspect ratio, it hands you a blank latent sized so the total pixel count stays put. That's it, and that's the whole appeal.

    Why you'd reach for it: SDXL-style models were trained at a set area (~1MP) across a handful of ratios - 1024², 1152x896, 1216x832, and friends. Stock Empty Latent Image makes you eyeball width and height by hand, and the classic mistake is cranking one dimension without the other, so a "portrait" run silently becomes a 1.7MP render that's way off the model's comfort zone. This node fixes the "area drifts as you change ratio" problem in one knob: pick your ratio, and the pixel budget stays constant.

    How it works

    The math is in calc_resolution, and it's refreshingly honest. You give it aspect_w and aspect_h (say 3 and 4 for a portrait), then fixed_side decides what base means:

    • none - area = base². So width = sqrt(base² × ratio), height = width ÷ ratio. At base 1024 this is always ~1MP, whatever ratio you throw at it. This is the mode that matches how SDXL was actually trained.
    • short - pins the short side to base. Want a 1536-wide landscape with a 640 short side? Here you go.
    • long - pins the long side instead. Useful when you need to hit a specific edge length for a video or tiling pipeline.

    The one genuinely smart bit is the rounding. Dimensions round to step (default 8, so you stay in the multiples-of-8 the SD1.5/SDXL VAE expects). But in "none" mode it rounds width to lcm(step, aspect_w) and height to lcm(step, aspect_h), so the aspect ratio survives the rounding instead of getting quietly mangled by a few pixels. Small touch, saves you the "why is my 3:2 now 601x401" confusion.

    The latent itself is just torch.zeros([batch_size, 4, height//8, width//8]) - 4 channels, 8× downsampled, the standard SD1.5/SDXL VAE shape. Wire the latent output into a KSampler and go.

    Inputs and outputs that matter

    You'll actually touch four things. base (default 1024) is your resolution budget, fixed_side picks the mode above, and aspect_w/aspect_h are the ratio. Then preset is a lazy shortcut: 16 common ratios from 3:1 landscape down to 1:3 portrait, and picking one just fills in aspect_w/aspect_h for you. batch_size (default 1) duplicates the blank latent if you're building a batch workflow; step you'll usually leave at 8.

    Outputs: latent (goes to KSampler), plus width and height as INTs - handy if you want other nodes to mirror the same resolution. The node also shows the computed dimensions live on its face, and there's a switch ⇅ button that swaps width and height in one click. Nice for flipping a landscape layout to portrait without re-entering the ratio.

    Installing it

    ComfyUI Manager → search comfy-aspect-ratios → Install, then restart. Or the manual route:

    cd ComfyUI/custom_nodes
    git clone https://github.com/jupo-ai/comfy-aspect-ratios
    

    Then restart ComfyUI. No pip dependencies, no model files, no requirements.txt to babysit - it's just PyTorch and the ComfyUI API. About as safe a custom node as exists in the ecosystem.

    Where people get burned

    • It's SDXL-family only in practice. The latent is hardcoded to 4 channels. Flux and the newer 16-channel VAEs will not take this shape - you'll get shape errors or garbage. For Flux, stick with EmptySDXLSize/EmptyLatentImage-style nodes that know about its VAE.
    • The latent is zeros, on purpose. A blank latent decodes to a flat, near-black image - that's normal. The noise comes from the sampler; this node is just the canvas.
    • batch_size only duplicates. It doesn't do anything clever like differing prompts - you still need a separate conditioning setup per item.

    For day-to-day SDXL work it's quietly the better default: constant pixel budget, ratio-safe rounding, and no install friction.

    Categoryjupo/AspectRatios

    Inputs (7)

    NameTypeDefaultDescription
    baseINT1024
    fixed_sideCOMBO3 options: none, short, long
    stepINT8
    aspect_wINT1
    aspect_hINT1
    presetCOMBO16 options: none, [landscape] 3:1, [landscape] 7:4, [landscape] 19:13, [landscape] 3:2, [landscape] 7:5, +10
    batch_sizeINT1

    Outputs (3)

    NameTypeDescription
    latentLATENT
    widthINT
    heightINT