Nodes/ComfyUI_Swwan/LayerUtility: ColorImage (Swwan)
ComfyUI Node

LayerUtility: ColorImage (Swwan)

A solid-color canvas in one node

By aining2022·Created 9 months ago·Updated 10 days ago· 33
LayerUtility: ColorImage (Swwan)
    • image
    width512
    height512
    color#000000

    Every once in a while you need a flat, solid-color image to composite something onto - a placeholder canvas, a colored backdrop behind a transparent PNG, a neutral base for a blend. Stock ComfyUI doesn't make this obvious, and the common answer ("just load a PNG you made") is silly when a node can build it. LayerUtility: ColorImage is that node: you give it width, height and a color, and it hands back a solid IMAGE tensor.

    This is the dependency-free re-implementation in ComfyUI_Swwan of a node that originally came from ComfyUI_LayerStyle - the source docstring says outright it was written "without depending on ComfyUI_LayerStyle." So if you've used LayerStyle's ColorImage, this is the same idea in a smaller package, sitting in the 😺dzNodes/LayerUtility menu category.

    Inputs and outputs

    Three required inputs, no options, no lists:

    • width (default 512) - image width in pixels
    • height (default 512) - image height
    • color (default #000000) - the fill color

    The color string is parsed by PIL's color parser, which is more forgiving than you'd expect. Hex works (#FF8800), with or without the hash - the node even accepts a bare 6-digit hex like FF8800. Named colors work too, because PIL knows them: "red", "white", "mediumseagreen". And rgb(r,g,b)-style strings are accepted if that's your muscle memory. If PIL can't parse it, you get a clear error naming the offending string, which is a nicer failure than most nodes bother with.

    Output: one image, shape 1 × height × width × 3 - a single-image batch, standard ComfyUI, ready to wire into an ImageBlend background socket, a concat, or an alpha composite chain.

    How it works

    Trivial, and that's the point. It converts the color to RGB, builds a 1×1×1×3 tensor of the values scaled to 0–1, and expands it to the requested dimensions. No GPU involvement worth mentioning, no model, no randomness - it's deterministic and instant, so it's safe to put in the hot path of a loop or a video frame chain.

    Installing it

    It ships in ComfyUI_Swwan:

    cd ComfyUI/custom_nodes
    git clone https://github.com/aining2022/ComfyUI_Swwan
    pip install -r ComfyUI_Swwan/requirements.txt
    

    Or install the pack via ComfyUI Manager, search "ComfyUI_Swwan".

    Where people get burned

    Not much to burn here - the one trap is assuming the output has an alpha channel. It doesn't; it's a plain 3-channel RGB image. If you need a transparent canvas for alpha work, you want the RGBA Safe nodes in this same pack, not a solid color. And if the color just doesn't look right, double-check you're feeding a string - a stray number gets str()'d and PIL may parse it as a grayscale value, giving you a gray rectangle when you expected a red one.

    Category😺dzNodes/LayerUtility

    Inputs (3)

    NameTypeDefaultDescription
    widthINT5124–99999
    heightINT5124–99999
    colorSTRING#000000

    Outputs (1)

    NameTypeDescription
    imageIMAGE