Nodes/ComfyUI-ZML-Image/ZML_双整数V2
ComfyUI Node

ZML_双整数V2

Random or indexed resolution from a preset list — for batch variety

By zml-w·Created about a year ago·Updated 2 months ago· 218
ZML_双整数V2
    • 预设宽
    • 预设高
    • help
    预设宽832,1024,1216
    预设高1216,1024,832
    索引值0
    随机宽高对应true

    Type in a few resolutions, and this node hands you one of them - by index when you pick a valid one, or at random when you don't. It's the natural next step up from the plain ZML_双整数: instead of two fixed numbers you get a comma-separated preset list for width and a matching list for height, with the choice driven by an index or by randomness. Its natural home is batch generation where you want each render to roll a different aspect ratio without hand-editing the latent size every run.

    How it works

    Two text fields, 预设宽 and 预设高, each holding comma-separated integers - defaults 832,1024,1216 and 1216,1024,832, which are the standard portrait/square/landscape triple. The node parses both lists, then decides:

    • 索引值 > 0 and within range of both lists → pick that position (1-based) from each list.
    • 索引值 = 0 or out of range → random choice.
    • 随机宽高对应 on → the same index is used for both lists, so you get matched pairs (832×1216, 1024×1024, 1216×832). Off → width and height are chosen independently, so you can roll 832×832 or 1216×1216.

    The key engine detail: the node overrides IS_CHANGED to return float("nan"), which tells ComfyUI the result always changes - so random mode genuinely re-rolls on every execution instead of getting cached. That's the mechanism behind "different resolution each run."

    The inputs

    • 预设宽 / 预设高 - comma-separated integer lists.
    • 索引值 - 0–114514. Zero (or out of range) means random.
    • 随机宽高对应 - matched pairs vs. independent rolls.

    Outputs: 预设宽 (INT), 预设高 (INT), and help (STRING) - the help output is the author's friendly usage essay, worth reading once because it explains the exact index-vs-random behavior.

    Installing

    Pack standard:

    cd ComfyUI/custom_nodes
    git clone https://github.com/zml-w/ComfyUI-ZML-Image
    

    restart or ComfyUI Manager. Translation patch at https://github.com/zml-w/ZZZ_ZML_English_Patch for English labels.

    Common issues

    The off-by-one index semantics surprise people: 索引值 1 is the first preset (it does 索引值 - 1 internally), and 0 means random - so you can't "pick the first item" with the default 0. If you want fixed first-item behavior, type 1. Second, list length mismatches: if 预设宽 has 3 items and 预设高 has 4, matched mode truncates to the shorter list and independent mode samples each separately - harmless, but confusing if you didn't mean it. And remember the IS_CHANGED override means every execution re-rolls in random mode, including the first, so a "fixed" workflow with 索引值 0 gives you a different resolution on every run - which is exactly the point for batch variety and exactly the trap if you forgot random mode was on.

    Categoryimage/ZML_图像/整数

    Inputs (4)

    NameTypeDefaultDescription
    预设宽STRING832,1024,1216
    预设高STRING1216,1024,832
    索引值INT00–114514
    随机宽高对应BOOLEANtrue

    Outputs (3)

    NameTypeDescription
    预设宽INT
    预设高INT
    helpSTRING