Nodes/ZMG PLUGIN/Text To Image
ComfyUI Node

Text To Image

The name is a trap — this renders text to an image, it doesn't generate one

By fq393·Created 2 years ago·Updated 7 months ago· 8
Text To Image
    • image
    textHello World 你好世界
    font_name默认字体
    font_size48
    text_color#000000
    background_color#FFFFFF
    padding30
    line_spacing1.2

    Let's get the important thing out of the way: this node does not generate images from a text prompt. No model, no diffusion, no KSampler. It types your text onto a canvas with PIL, like a caption generator or a sign-maker, and hands you an IMAGE you can feed into the rest of your workflow. "Text To Image" here means literally rendering text to an image. If you googled this expecting Stable Diffusion text-to-image, that's the trap - close the tab and look for a Checkpoint Loader plus KSampler instead. If you actually need a text rendered as pixels, keep reading, because that's genuinely useful.

    What it actually does

    You give it text, it renders it with a truetype font onto a dynamically sized canvas, and outputs an IMAGE tensor. The canvas grows to fit the text, wrapped intelligently - it's CJK-aware, so mixed Chinese/English lines wrap at sensible points rather than mid-character. It ships a Songti (宋体) font in the pack's fonts/ folder for exactly this, and the font dropdown picks it up automatically (along with a "default" system font). Output is capped at a 1024px max width so it stays pipeline-friendly.

    Inputs that matter

    • text - multiline. The default is Hello World\n你好世界, which tells you everything about who built this.
    • font_name - 默认字体 or Songti. Adding your own .ttf/.ttc/.otf to the pack's fonts/ folder makes it appear here.
    • font_size - 12–200, default 48.
    • text_color / background_color - hex strings like #000000 / #FFFFFF. Both 3- and 6-digit hex work.
    • padding - margin in pixels around the text, 0–100, default 30.
    • line_spacing - line-height multiplier, 0.5–3.0, default 1.2.

    Outputs

    One output: image (IMAGE tensor). It's OUTPUT_NODE = True, so you'll see it in the UI as an output/preview. From there it can go anywhere an image goes: VAE Encode for img2img, a Combine Image+Audio node as a frame, or a text-overlay into a collage workflow. Making a title card for an AnimateDiff clip or watermarking a batch is exactly the sweet spot.

    Gotchas

    The word-wrap logic does the heavy lifting but maxes out - very long unbroken strings get wrapped by character, which for a 1024px cap is fine until it isn't. Colors are parsed strictly: garbage hex silently defaults to black, which can look like the node "did nothing." And there's no transparency option - background is always a solid color, so you can't get a text-only overlay with alpha from this. Use a compositing node to punch the text over an image instead.

    Installing

    Part of the ZMG pack. ComfyUI Manager → search "ZMG" / "ComfyUI-ZMG-Nodes", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/vanche1212/ComfyUI-ZMG-Nodes
    cd ComfyUI-ZMG-Nodes
    pip install -r requirements.txt
    

    Restart, find it under ZMGNodes/image. Needs Pillow (for the rendering) and torch (to build the tensor), both in the pack's requirements. Useful tool - just remember the name is doing something different from what you think.

    CategoryZMGNodes/image

    Inputs (7)

    NameTypeDefaultDescription
    textSTRINGHello World 你好世界
    font_nameCOMBO默认字体2 options: 默认字体, Songti
    font_sizeINT4812–200
    text_colorSTRING#000000
    background_colorSTRING#FFFFFF
    paddingINT300–100
    line_spacingFLOAT1.20.5–3

    Outputs (1)

    NameTypeDescription
    imageIMAGE