Nodes/ComfyUI 1hewNodes/String Ratio Jimeng
ComfyUI Node

String Ratio Jimeng

Hand the API a ratio it will actually accept

By 1hew·Created about a year ago·Updated 2 days ago· 33
String Ratio Jimeng
  • image
  • string
selection1:1

What it's for

Jimeng is ByteDance's image product - Dreamina outside China, riding the same closed Seedream line the KB's ByteDance panel describes as never having shipped an open weight. Like most hosted image models, it doesn't take "whatever aspect ratio your image happens to be". It takes a fixed enum: nine-ish buckets, and you pick one. Ask for something off-list and you get an error, or a silently stretched image, depending on how the wrapper was written.

String Ratio Jimeng is the adapter. It takes an image and returns the label of the closest ratio in that enum, as a plain string you can pipe into whatever node exposes the Jimeng ratio input. If nothing is connected it just passes your manual selection through, which makes it a tidy little switch: automated when you're editing an existing image, manual when you're generating from scratch.

How it works

The selector's preset set is: 21:9, 16:9, 3:2, 4:3, 1:1, 3:4, 2:3, 9:16. Default is 1:1.

If image isn't connected, the node returns selection unchanged.

If it is, each frame's width / height gets compared against every preset and the winner is chosen by the smallest |log(image_ratio) − log(preset_ratio)|. The log distance matters: it's scale-symmetric, so a 3:2 image is as close to 3:2 as a 2:3 image is to 2:3, and a 4:3 near-miss isn't penalised differently from its reciprocal. Plain absolute difference between ratios would bias toward the wider presets and quietly send your portrait crop to a landscape bucket.

Two consequences fall out of that. The node never returns a ratio outside the enum - that's its whole job, an output that the API will accept without a fight, even if it isn't the ratio you actually have. And multi-frame batches produce a multi-line string, one ratio per frame, because the node loops over the batch.

Inputs and outputs

selection (COMBO, default 1:1) and optional image (IMAGE). One output: string.

Wiring: string goes into whatever your Jimeng/Seedream node uses for its ratio - a text field is direct, and for a dropdown-style input the pack's Text to Any node exists to hand a plain string to a widget that expects a combo. If you'd rather work locally, the same pack ships Image Resize Jimeng, which uses the matching preset family so a preview render and the API call land on the same shape; the sibling nodes String Ratio Gpt20Image and String Ratio Gemini31FlashImage do the identical job for those models with their own, different preset sets.

The image input being connected overrides selection entirely. There's no "blend the two" mode - connect an image and the dropdown becomes decorative.

Install

ComfyUI Manager → search 1hewNodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes

Restart. This node needs nothing beyond torch and stdlib math - the pack's heavyweight requirements (ultralytics, rembg, transparent-background, onnxruntime, av) are for its detection and video nodes. It's written against the current comfy_api.latest schema, so update ComfyUI if the pack won't import.

Common issues

The output is several lines and the API node rejected it. You fed a batch. This is the most common way this node bites: Load Video to Image or any batched image source makes it emit one ratio per frame, and almost every hosted API expects a single value. Sample or index the batch down to one image first.

I connected an image and my dropdown selection stopped mattering. By design - see above. Disconnect or bypass the node if you want the manual value.

The ratio it picked isn't the ratio of my image. Correct, and intended. Nearest supported bucket, not exact. If you need the image to become that ratio rather than be described by it, resize it - the string is metadata for the API, not a transform.

I need an actual resolution, not a ratio. Different node. String Resolution in this pack infers a 0.5k / 1k / 2k / 4k tier; Image Resize Jimeng turns the preset into pixels.

Category1hewNodes/text

Inputs (2)

NameTypeDefaultDescription
selectionCOMBO1:18 options: 21:9, 16:9, 3:2, 4:3, 1:1, 3:4, +2
imageoptIMAGE

Outputs (1)

NameTypeDescription
stringSTRING