Nodes/Comfyui_PDuse/PD:ratio selector
ComfyUI Node

PD:ratio selector

The ratio-to-pixels calculator every multi-ratio workflow needs

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD:ratio selector
    • ratio
    • width
    • height
    • filename_prefix
    • max_size
    aspect_ratio1:1
    max_size1024

    Pick an aspect ratio, give it a long edge, and it hands you ready-to-use pixel dimensions. That's the whole node, and it's the quiet hero of the PDuse ratio toolkit: PD:ratio selector turns 2:3 + 1024 into width = 680, height = 1024 - rounded to a multiple of 8, the way AI image generation actually wants it - plus a filename prefix you can drop straight into a save node. The README calls it "a very simple logic, mainly to handle output size" and that's exactly right. Simple, but it stops you from doing the math wrong at 2 a.m.

    It's the calculator half of the pack's ratio system. Its sibling PDselector-image picks the image for a ratio; this one computes the canvas. Wire width/height into an Empty Latent and the ratio into a filename builder and you've got a workflow that stays in sync across every ratio you render.

    How it works

    Parse the ratio into two integers, put the longer side at max_size, scale the shorter side proportionally, then round both to the nearest multiple of 8. That rounding is the important bit - diffusion models are happiest on 8-divisible dims, and hand-rounding a portrait ratio to 8 is precisely the kind of off-by-8 mistake that gives you a latent error you'll blame on everything else.

    The filename_prefix output is built like image=2x3-680x1024 - ratio with the colon swapped for an x, then the computed dims. That's a ready-made save prefix that encodes the whole layout in the filename, which is a nice touch if you generate the same thing in several ratios and want the files distinguishable at a glance.

    The inputs that matter

    • aspect_ratio - enum with 1:1, 3:4, 4:3, 2:3, 3:2, 9:16, 16:9. A dropdown, so you can't typo it.
    • max_size (256–8192, step 8, default 1024) - the longest edge.

    Outputs: ratio, width, height (INT), filename_prefix (STRING), and max_size (STRING - yes, it echoes your number back as a string; handy if you need it in a text pipeline).

    Installing it

    Part of Comfyui_PDuse by 7BEII. ComfyUI Manager (search "PDuse") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/7BEII/Comfyui_PDuse.git
    cd Comfyui_PDuse
    pip install -r requirements.txt
    

    Restart. No models to download; deps are numpy, Pillow, scipy, opencv-python, torchvision. Chinese-first docs.

    Where people get burned

    The rounding means the actual pixel ratio is never exactly the aspect ratio - 2:3 at max_size 1024 gives 680×1024, which is 0.664 vs the ideal 0.667. For empty latents and checkpoints that's close enough that nobody cares; just don't use the dims to crop something that demands precise proportions. Also note the ratios are locked to those seven - no custom 7:4 without editing py/image_ratio selector.py. And that max_size output is a string even though you typed an int, so don't wire it into an INT socket expecting the number.

    CategoryPDuse/Image

    Inputs (2)

    NameTypeDefaultDescription
    aspect_ratioCOMBO1:17 options: 1:1, 3:4, 4:3, 2:3, 3:2, 9:16, +1
    max_sizeINT1024256–8192

    Outputs (5)

    NameTypeDescription
    ratioSTRING
    widthINT
    heightINT
    filename_prefixSTRING
    max_sizeSTRING