ComfyUI Node

Auto Aspect Latent

Stop doing the 16:9 math in your head

By kaipard·Created about a year ago·Updated about a year ago· 1
Auto Aspect Latent
    • latent
    width512
    use_aspect_ratio
    aspect_ratio
    height_value512
    batch_size1

    Every text-to-image workflow in ComfyUI starts with the same boring step: telling the sampler how big the image should be. The built-in way is the Empty Latent Image node - pick width, pick height, done. Auto Aspect Latent is that node with one upgrade: a dropdown of preset aspect ratios that computes the height for you. Set a width, pick 9:16, and it hands you a latent sized for a phone screen without you doing division.

    That's the whole pitch, and it's honest. It's a convenience node, not a power tool. If you only ever render 1024×1024, you don't need it. If you bounce between YouTube thumbnails, portrait ads, and square avatars, the presets genuinely save you a tiny bit of arithmetic every day. And it costs you nothing to install - this pack is a single file of logic with zero dependencies.

    How it actually works

    Under the hood it does exactly what ComfyUI's own Empty Latent Image does: it creates a tensor of zeros shaped like [batch_size, 4, height/8, width/8]. That /8 is the important part. Diffusion models don't work in pixels - the VAE compresses images into a latent space that's 8× smaller on each side (SD 1.5, SDXL, and Flux all use the same 8× downsample), and the sampler works in that compressed space before the VAE decoder turns it back into an image. So a 512×512 image is actually a 64×64 latent. Zeroes, not noise - the sampler adds the noise itself, so a blank latent is correct and normal.

    When use_aspect_ratio is set to "true", the node computes height = int(width * ratio) from the preset; set it to "false" and it just uses your height_value. Then it floors both dimensions down to a multiple of 8 (width // 8).

    The inputs that matter

    Only two inputs really matter for most people:

    • width - the base size you're working from (default 512, range 64–4096).
    • use_aspect_ratio / aspect_ratio - flip it to "true" and pick from the nine presets: 1:1, 4:3, 16:9, 9:16, 3:4, 2:3, 3:2, 1:2, 2:1.

    When you don't use a ratio, height_value steps in (also 64–4096). batch_size generates multiple latents at once, but you almost never need it above 1 unless you're doing a batch render.

    The single output, latent (type LATENT), wires straight into the latent input of a KSampler, which is the only sensible thing to connect it to.

    One genuine bug

    Read the source and there's a trap waiting for you: the 3:4 preset is broken. Its ratio maps to 1.0 instead of 4/3, so selecting 3:4 at width 512 gives you a square, not the portrait you asked for. Every other preset is correct (verified against the code - 16:9 gives 0.5625, 2:3 gives 1.5, and so on). If you want a 3:4 portrait, use 2:3 (it's the same orientation at slightly different crop) or set use_aspect_ratio to "false" and type the height. Worth knowing before it silently squares all your portrait posts.

    Also note the node rounds down to multiples of 8, not 64. Flux is picky about dimensions divisible by 64, and other models just play nicer with round numbers - so feed it widths like 1024 or 896 rather than 1005 and you'll have fewer surprises.

    Installing it

    The easy path is ComfyUI Manager: search for Auto Aspect Latent Generator (or comfyui-auto-latent-size) and hit install. Or clone it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kaipard/comfyui-auto-latent-size
    

    Restart ComfyUI and it shows up under latent → generator → Auto Aspect Latent. There's no requirements.txt and no model files to download - it only imports torch, which ComfyUI already runs on. The whole node is one auto_aspect.py file, which also means there's basically nothing that can break during install. Security-minded folks will still appreciate that this one has no install.py to run untrusted code, unlike some of the bigger packs.

    Bottom line

    A small, unambitious quality-of-life node that does one job and does it mostly right. The 3:4 preset bug is real and annoying, but every other preset behaves, the install is painless, and if you're tired of computing heights for platform crops it's a fair little add-on. Just don't expect more than a fancy Empty Latent Image with a calculator attached.

    Categorylatent/generator

    Inputs (5)

    NameTypeDefaultDescription
    widthINT51264–4096
    use_aspect_ratioCOMBO2 options: true, false
    aspect_ratioCOMBO9 options: 1:1, 4:3, 16:9, 9:16, 3:4, 2:3, +3
    height_valueINT51264–4096
    batch_sizeINT11–99

    Outputs (1)

    NameTypeDescription
    latentLATENT