Nodes/CFE_comfyui/CFE Aspect Ratio
ComfyUI Node

CFE Aspect Ratio

Stop doing aspect-ratio math in your head

By CpreForEver·Created 2 years ago·Updated 2 years ago· 0
CFE Aspect Ratio
    • latent
    • clip_width
    • clip_height
    type
    resolution
    megapixel
    clip_size1.0
    batch_size1

    EmptyLatentImage is the node everyone starts with, and then you spend a while doing mental math every time you want a 9:16. "Okay, if it's 1024 tall... no wait, it's the width..." CFE Aspect Ratio is the version where that math already happened.

    Pick a shape, pick a ratio, pick how many megapixels your model family likes, and it hands you a ready-to-use empty latent plus the pixel width and height as integers. It exists because every model family has a native resolution band, and generating outside that band is where the stretched anatomy and tiled patterns come from. The node bakes in the three big families - SD 1.5 at half a megapixel, SDXL at 1 MP, FLUX at 2 MP - so you get a size that actually matches what the model was trained on instead of whatever your ratio math converged to.

    How it works

    Under the hood it does exactly what you'd hope: takes the ratio, multiplies it against the megapixel target, and works out a width and height. Both dimensions get rounded to a multiple of 64 - the author's code comment on that step admits he's not entirely sure why it works, just that it does, which is the energy of this entire pack. The latent it creates is all zeros, spatially downsampled 8× (that's the // 8 in the shape), which is the standard empty latent every txt2img graph starts from.

    The inputs, and only a couple of them matter:

    • type - square, portrait, or landscape. This just decides which side is long.
    • resolution - the eight preset ratios, from 1:1 out to 9:21.
    • megapixel - ".5 MP (SD1.5)", "1 MP (SDXL)", or "2 MP (FLUX)". This is the one that actually decides the size.
    • clip_size - despite the name, this has nothing to do with CLIP. It multiplies the output width and height (default 1). The tooltip is honest about it; the name isn't.
    • batch_size - how many identical latents to create (default 1). Safe to ignore until you're batching.

    The three outputs are latent (LATENT), which goes into your sampler's latent input, plus clip_width and clip_height as plain integers - handy if anything downstream wants to know the real pixel size without you recomputing it.

    Gotchas

    The empty latent assumes full denoise. If you're doing img2img at denoise below 1, you want the encoded image latent instead, not this. And batch_size goes up to 4096, which is a lot of VRAM - just because it's in the schema doesn't mean you should run it. Flux at 2 MP is genuinely fine (flow-matching models handle resolution slack far better than SDXL, which wants to stay near its trained ratios), so don't feel like you have to baby it down.

    Installing it

    This is one of several nodes in ctefer/CFE_comfyui, a small personal pack. Install via ComfyUI Manager (search "CFE" - the pack title is CFE_comfyui) and restart, or clone it manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ctefer/CFE_comfyui
    

    No requirements.txt, no model downloads, nothing extra to install. If you already have this pack for one of the Flux nodes, this one came along for free. Worst case, it's a nicer way to build latents than EmptyLatentImage, and it costs you nothing to try.

    CategoryCFE/image

    Inputs (5)

    NameTypeDefaultDescription
    typeCOMBO3 options: square, portrait (w:h), landscape (h:w)
    resolutionCOMBO8 options: 1:1, 2:3, 3:4, 4:7, 7:9, 8:15, +2
    megapixelCOMBO3 options: 1 MP (SDXL), 2 MP (FLUX), .5 MP (SD1.5)
    clip_sizeFLOAT1.01–10Multiplies the output width and height values
    batch_sizeINT11–4096The number of latent images in the batch.

    Outputs (3)

    NameTypeDescription
    latentLATENT
    clip_widthINT
    clip_heightINT