Nodes/ComfyUI-bitpoet-keywordsize/Determine Size by Keyword in Prompt [BitPoet]
ComfyUI Node

Determine Size by Keyword in Prompt [BitPoet]

Type 'portrait' in your prompt, get a 1216x832 canvas instead of 1024x1024

By BitPoet·Created 5 months ago·Updated 5 months ago· 0
Determine Size by Keyword in Prompt [BitPoet]
    • prompt
    • width
    • height
    prompt
    size_definitions[default]:1024x1024
    remove_if_foundtrue

    Every so often someone on r/comfyui asks the same question: "can I change the resolution based on a keyword in my prompt?" - meaning, if the prompt says portrait, don't render the default 1024x1024, render 832x1216 instead. The usual answers involve chaining StringContains nodes into an If-ANY-execute branch, and honestly, that works. It's also clunky, and it gets worse with every aspect ratio you add.

    The author of this pack, Bit_Poet, answered that question by just… building the thing and dropping a link: "Here's a very simple and crude example of a custom node that does this without any plausibility checks." That link is this pack. One node, about 40 lines, zero dependencies. You type portrait anywhere in your prompt, and your workflow switches to 1216x832. That's the entire job, and it does it cleanly.

    Why you'd actually reach for it

    If you generate at one fixed resolution forever, you don't need this node. You need it the moment your resolution should follow your prompt - wildcard-driven prompts, aspect-ratio experiments, batch runs where half the images should be landscape and half should be square. Generating at a model's trained aspect ratios matters (SDXL's 1024, 1152x896, 1216x832, 1344x768 family is the classic case - straying off-ratio is how you get stretched anatomy), and this is the least-friction way to switch between those shapes per-prompt. Wire its width and height into an Empty Latent Image and its prompt into a CLIP Text Encode, and the canvas just matches what you wrote.

    How it works

    You feed it a prompt plus a text block of definitions, one keyword:WIDTHxHEIGHT per line. For each line it checks whether the keyword is a substring of the prompt; the first line that matches wins, and it returns that size. A special [default] line sets the fallback used when no keyword matches, and lines starting with # are ignored as comments. [default]:1024x1024 is what you get out of the box.

    The three inputs and what they do

    • prompt - your prompt text, usually fed in from a text/wildcard node.
    • size_definitions - the multiline list, keyword:WIDTHxHEIGHT per line, # for comments, [default] for the fallback.
    • remove_if_found - defaults on. When a keyword matches, it's stripped out of the prompt output so portrait doesn't leak into your actual generation prompt.

    Outputs: prompt (the prompt, minus the matched keyword if that toggle is on), width and height (integers for your latent/KSampler).

    Installing it

    ComfyUI Manager handles it - search "keywordsize" or "bitpoet" and install. Or do it by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/BitPoet/ComfyUI-bitpoet-keywordsize
    

    Then restart ComfyUI. That's the whole install: the node is pure Python stdlib, no requirements.txt, no model downloads, no GPU deps. It's GPLv3 like the pack says.

    Where people get burned

    The author's "no plausibility checks" warning is literal, and it's where all the traps live:

    • It doesn't clean whitespace. portrait: 832x1216 or portrait :832x1216 will misparse. Write portrait:832x1216, no spaces.
    • Keyword matching is a case-sensitive substring check. cat will match inside category, and with remove_if_found on, replace() strips every occurrence of that string, not whole words. Pick distinctive keywords - [square], --landscape, {portrait} - and you sidestep both problems.
    • First matching line wins. If two lines could both match, order matters; put your most specific keyword first.
    • Nothing validates the size half. A typo like 832x12o6 sails straight through to the width/height outputs and blows up downstream, so proofread your definitions.

    It's not the node to reach for if you need conditional logic beyond size (use a proper flow-control pack for that). But for "prompt says it, canvas does it," this is a refreshingly small, honest tool.

    Categorybitpoet/utils

    Inputs (3)

    NameTypeDefaultDescription
    promptSTRING
    size_definitionsSTRING[default]:1024x1024
    remove_if_foundBOOLEANtrue

    Outputs (3)

    NameTypeDescription
    promptSTRING
    widthINT
    heightINT