ComfyUI Node

Hex to Color

Pip hex colors into color widgets without fighting a color wheel

By longgui0318·Created 2 years ago·Updated about a year ago· 1
Hex to Color
    • color
    hex_string#000000

    "Hex to Color" converts a hex string like #2E5A88 into a COLOR-typed value that you can plug into any node with a COLOR input. On its own it's the least exciting node in this pack - it literally prepends a # if you forgot it and hands the string back - but it exists to solve a genuinely annoying ComfyUI problem: COLOR inputs are normally color-picker widgets you click with a mouse.

    That's fine when you're setting one color by hand. It's miserable when you want to drive a color from a prompt template, randomize it across a batch, or send it in from an API. COLOR widgets don't take text input, so there was no clean way to feed them a value programmatically. This node is the bridge: any string node (or a literal hex you type into the widget) becomes a proper COLOR output, and that plugs straight into the picker-based input.

    How it works

    Trivial, and that's fine: it checks whether the string starts with #, adds it if not, and returns the result tagged as the COLOR type. There's no parsing, no validation, no conversion to RGB numbers - ComfyUI's COLOR type is just a string under the hood, so the "conversion" is mostly about giving the graph the right type so the wire will connect.

    Inputs and output

    • hex_string (STRING, default #000000) - the color. #RRGGBB or bare RRGGBB both work.
    • color (COLOR) - the output.

    The one real gotcha

    No validation. Feed it "blue" or "notacolor" and it passes through happily, and then the node consuming it may throw or do something weird. Keep it to #RRGGBB and you're safe. Also note it's 6-digit hex only in practice - if you feed #RGB shorthand or an 8-digit #RRGGBBAA, downstream nodes that expect the picker's format can misbehave.

    Where it shines

    The obvious pairing is in this same pack: Image Remove Alpha takes a COLOR fill_color, and driving that from Hex to Color means you can flatten a cutout onto a color that comes from a data source instead of a hand-picked swatch. More generally: color-templated workflows, batch variations where the background hue changes per run, or any time you're pasting hex codes from a brand palette into a graph without squinting at a color wheel. It's a two-node habit that pays off once you need it more than once.

    Installing it

    It's part of the longgui0318/comfyui-common-util pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/longgui0318/comfyui-common-util
    cd comfyui-common-util && pip install -r requirements.txt
    

    Then restart ComfyUI. Or use ComfyUI Manager and search "comfyui-common-util". The README is minimal and requirements.txt only pins opencv-python, but the pack imports scipy, scikit-image, and PyWavelets at load - if it fails to appear, pip install scipy scikit-image PyWavelets then restart.

    Categoryutils/color

    Inputs (1)

    NameTypeDefaultDescription
    hex_stringSTRING#000000

    Outputs (1)

    NameTypeDescription
    colorCOLOR