PD:string-to-ratio-combo
A ratio string adapter that quietly saves you from combo dropdowns
- combo
It converts text into a dropdown value, and that's it
PD:string-to-ratio-combo (PDStringToRatioCombo) answers one annoying ComfyUI problem: some nodes only accept a ratio through a fixed combo dropdown (1:1, 3:4, 4:3, 2:3, 3:2, 9:16, 16:9), but your ratio is coming in as a plain text string - typed in a box, read from a file, or output by another node. This node takes that string and, if it matches one of the seven known ratios, hands you back the typed combo value. If it doesn't match, it returns your chosen fallback.
That's the entire job, and it's a good one. The pack's ratio-selector family (PDselector-string, the ratio image selector, the ratio crop nodes) all generate strings like "2:3" or "680x1024", and any of them can feed this adapter when the downstream node insists on a real combo. Think of it as a small type-coercion shim - the plumbing-layer concept the KB covers in comfyui-node-plumbing.md: a node whose only purpose is to bend the graph so values flow.
How it works
The source is about as short as it gets. There's a hardcoded list RATIO_COMBO_TYPE of those seven ratios. The convert function strips whitespace from your string, checks membership in the list, and returns it if present - otherwise it returns fallback. No normalization, no fuzzy matching, no hidden parsing.
Inputs and outputs
string- your free-text ratio. This is where you'd wire the output ofPDselector-stringor type a value.fallback- a dropdown of the seven ratios. This is your safety net: whatever you pick here is what you get whenstringisn't one of the seven.- Output:
combo- the typed ratio, guaranteed to be one of the seven.
Installing it
It ships in Comfyui_PDuse, so:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse.git
cd Comfyui_PDuse
pip install -r requirements.txt
Or install "Comfyui_PDuse" via ComfyUI Manager and restart. No extra dependencies beyond what the pack pulls in (mostly things ComfyUI already has).
The gotcha nobody warns you about
Because it does no normalization, "2 : 3", "2x3", "2/3" or "0.67" all fail the membership check and silently drop to fallback. If your upstream string isn't exactly 2:3, you'll get the wrong ratio with zero error message - the silent-fallback pattern this whole pack leans on. So either sanitize the string upstream (trim and fix separators) or set fallback deliberately to the ratio you want as the safe default. For the happy path - clean "N:N" strings - it just works, and it's the least fussy node of its kind.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| string | STRING | 2:3 | — |
| fallback | COMBO | 2:3 | 7 options: 1:1, 3:4, 4:3, 2:3, 3:2, 9:16, +1 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| combo | 1:1,3:4,4:3,2:3,3:2,9:16,16:9 | — |