Nodes/ComfyNodesPlus/CNP Random Resolution
ComfyUI Node

CNP Random Resolution

Let your workflow roll its own aspect ratio

By chemicalshock·Created 4 months ago·Updated 4 months ago· 0
CNP Random Resolution
    • width
    • height
    • resolution
    moderandom_ratio
    base_unit512
    min_steps1
    max_steps4
    fixed_width_steps2
    fixed_height_steps2
    orientationany
    ratio_modecommon
    randomise_orientationtrue
    seed0

    CNP Random Resolution picks a width and height for you, on a grid, from a seed you control. The point is exploration: instead of hand-setting 1024×1024 and hoping, you let a run grab a random aspect ratio from a sensible list - 512×1024, 1024×1536, 2048×1024 - and see what the model does with it. That's the batch-variation workflow ComfyUI is uniquely good at, except here the thing varying is the canvas, not just the seed.

    Everything it emits is a multiple of base_unit, so with the default 512 you get 512, 1024, 1536, 2048 - all multiples of 64, which keeps the VAE happy. No off-grid sizes that make latents or the VAE complain.

    Three modes

    • fixed - uses fixed_width_steps and fixed_height_steps directly. No randomness at all; effectively a nicer way to type a resolution.
    • random - picks a step count for width and for height independently.
    • random_ratio (default) - builds a curated set of aspect ratios from common pairs (1:2, 2:3, 3:4, and their landscapes) then picks one. This is the "surprise me, but make it sane" mode.

    Inputs that matter

    • mode - the three above.
    • base_unit - the grid size. 512 for SD1.5-era models, 1024 for SDXL/Flux native resolution. Step is 64, so you can't emit a dimension the VAE will choke on.
    • min_steps / max_steps - the range of base_units per side. Defaults 1–4, meaning 512–2048 at base 512.
    • orientation - any, square, portrait, or landscape. Force the shape when you need it.
    • ratio_mode - common (both orientations), vertical_common, horizontal_common, or free (any combination of steps).
    • seed - same seed, same resolution, every time.

    Outputs

    width (INT) and height (INT) go straight into the Empty Latent Image node's width/height inputs. There's also a resolution STRING ("1024 x 1536"), handy for a caption or to hand to CNP Format when you're saving images named by size.

    The gotcha that will trip you up

    The seed is a plain INT widget, not a ComfyUI seed control. There's no "randomize after generate" built in, so with the default seed of 0 you'll get the exact same resolution on every run. Great for reproducibility, very confusing if you expected a die roll. To actually randomize, feed it a fresh seed each run (bump the value, or wire in a random-seed node) - that's the whole trick to making this node do its job.

    Install

    cd ComfyUI/custom_nodes
    git clone https://github.com/chemicalshock/ComfyNodesPlus
    

    or ComfyUI Manager → "ComfyNodesPlus", then restart. No requirements.txt and no model files - it's pure Python stdlib, so it can't break your environment like the heavier utility suites.

    Troubleshooting

    • The node has no idea how much VRAM you have. base_unit 2048 with max_steps 4 is 8192² - a 67-megapixel latent that will OOM most cards. Dial max_steps down.
    • min_steps greater than max_steps? It silently swaps them rather than erroring.
    • It emits one resolution per node execution, and a fixed sampler batch shares it. For per-image variety in a batch, randomize the seed between runs rather than expecting one node call to vary mid-batch.
    CategoryComfyNodesPlus/Utils

    Inputs (10)

    NameTypeDefaultDescription
    modeCOMBOrandom_ratio3 options: fixed, random, random_ratio
    base_unitINT51264–4096
    min_stepsINT11–32
    max_stepsINT41–32
    fixed_width_stepsINT21–32
    fixed_height_stepsINT21–32
    orientationCOMBOany4 options: any, square, portrait, landscape
    ratio_modeCOMBOcommon4 options: free, common, vertical_common, horizontal_common
    randomise_orientationBOOLEANtrue
    seedINT00–18446744073709550000

    Outputs (3)

    NameTypeDescription
    widthINT
    heightINT
    resolutionSTRING