ComfyUI Node

DrawTextNode

Paint text onto any image region — and it'll follow the mask's angle

By infinigence·Created about a year ago·Updated about a year ago· 2
DrawTextNode
  • image
  • mask
  • image
words

If you've ever needed actual text baked into an image - a sign, a caption, a billboard - you know image generators mangle it, especially Chinese. DrawTextNode is a tiny utility from Infini-AI's ComfyUI-Infinigence-Nodes pack that renders real text into a masked region of an image, and the two things it does better than the average text-overlay hack are: it supports Chinese and English out of the box, and it rotates the text to match the mask's orientation. It's not a font-picker with 30 options; it's the "write this text in that region" workhorse for workflows where text has to exist as pixels before something else processes them.

How it works

The mechanism is straightforward and surprisingly clever. You feed it three things: the base image, a mask that defines where the text goes, and words - one line of text per region. Under the hood it runs OpenCV contour detection on the mask, throws out blobs smaller than ~50 pixels, sorts what's left top-to-bottom, then for each region:

  • runs a PCA on the contour's points to find the region's dominant axis,
  • rotates the text layer to line up with that axis (keeping it upright - it never flips your text upside down),
  • auto-shrinks the font size until the text fits inside the region's bounding box.

That last bit is why it feels magic: you don't set a font size, it just fits. The whole thing is powered by a bundled 23 MB Arial-Unicode font, which is what makes CJK rendering work without you hunting down a font file.

The inputs that matter

There are only three inputs and one output, so nothing to tune:

  • image (IMAGE) - the base image you're drawing onto.
  • mask (IMAGE) - this is the gotcha. It takes an IMAGE, not a MASK. If your mask comes out of a node as MASK (like LoadImage's second output or a segmentation node), you must convert it first with MaskToImage. The pack's own example workflow does exactly that.
  • words (STRING, multiline) - one line per region. The first region gets line 1, the second gets line 2, and so on; regions beyond your lines are left alone.
  • output image - the composite, ready for PreviewImage, SaveImage, or straight back into an img2img / video pipeline.

Installing it

Via ComfyUI Manager (search "ComfyUI-Infinigence-Nodes"), or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/infinigence/ComfyUI-Infinigence-Nodes

then restart ComfyUI. The pack's requirements.txt pulls in opencv-python, scikit-learn, numpy, pillow, and torch - nothing exotic, no model files to download (the font ships in the repo). If Manager installs it, it'll handle the pip deps for you.

Where people get burned

  • Black text only. The draw color is hardcoded to black. No color, font, or size widgets exist. If you need white or colored text, this is not the node.
  • The mask-as-IMAGE trap mentioned above. You'll plug a MASK in and get a type error; run it through MaskToImage first.
  • Only the first image in a batch gets processed. Feed it a batch of 8 and you get text on frame one only - an easy silent surprise.
  • If the bundled font file goes missing, the node logs a warning (in Chinese, so easy to overlook) and returns your image completely unchanged. No crash, just no text.

It renders text onto the image - it doesn't inpaint or blend. For clean results, mask a region that roughly matches where you want the text, then let an img2img pass naturalize it. For a pack with essentially zero public footprint, this node earns its keep if your workflow involves signs or captions - and it's one of the few text-overlay tools that won't choke on Chinese.

CategoryImage/Text

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
maskIMAGE
wordsSTRING

Outputs (1)

NameTypeDescription
imageIMAGE