Text Behind Image
The poster-style layering trick, done as one composite node
- Background
- Text Image
- Text Mask
- Foreground (RGBA)
- image
You've seen the effect even if you didn't know it had a name: a photo where big bold text sits behind the subject - the subject's silhouette cuts a hole in the text, or overlaps it, so it reads as one layered composition instead of a caption slapped on top. It's a genuinely popular design trick for posters, thumbnails, and social graphics, popular enough that people have built whole web apps around doing nothing else. This node gives you the same layering as a single compositing step inside ComfyUI, so it can live in the middle of a generation pipeline instead of being a separate manual editing pass.
How it works
Don't mistake this for a text-rendering node - it doesn't draw text and it doesn't know any fonts. What it does is composite four layers you hand it, in a fixed stacking order: your Background sits at the bottom, your Text Image (whatever rendered-text graphic you made elsewhere) gets placed on top of that using a Text Mask to control exactly where it's visible, and then your Foreground - an RGBA cutout of your subject, most likely from a background-removal step - goes on top of everything, so the subject visually sits in front of the text. Each of the two upper layers gets its own opacity control, so you can fade the text back or let the foreground subject sit at partial transparency for a ghosted effect.
Practically, you need two upstream pieces before you reach this node: something that renders text into an image plus a matching mask (this pack doesn't include a text-renderer, so that's coming from elsewhere in your graph - a font/text node from another pack, or hand-drawn), and a background-removal step to give you a clean RGBA subject cutout for the foreground slot.
The inputs and outputs that matter
Background- the base scene, plain image.Text Image- your rendered text or graphic, as an image.Text Mask- the MASK that tells the node where the text is actually visible versus transparent. This is what lets the subject "cut through" the text rather than the text just sitting flatly on top.Foreground (RGBA)- your subject cutout, with a real alpha channel, layered on top of everything.Foreground Opacity(0–1, default 1) - how strong the subject layer is over the composite.Text Image Opacity(0–1, default 1) - how strong the text layer is over the background.
Single output, image, and the node is flagged as an output node, so it can end a branch of your graph directly.
How to install it
Search KGnodes in ComfyUI Manager, or:
cd ComfyUI/custom_nodes
git clone https://github.com/shahkoorosh/ComfyUI-KGnodes.git
pip install -r requirements.txt
Restart, find it under Add Node → 🎨KG. Pure image compositing, no models to download.
Common issues & troubleshooting
All four images have to be the same size. This is the same requirement the pack's plain overlay node has (they share the underlying compositing logic), and it's the single most likely reason you'll get an error or a badly-offset result. Get your background, text image, text mask, and foreground cutout all matched in dimensions before they hit this node.
"Where do I even get the Text Image and Text Mask from?" This node composites; it does not generate. If you were expecting to type a string into this node and get styled text out, that's not what it does - you need a text-rendering node upstream (something that turns a font + string into an image and a matching alpha mask) feeding into these two inputs.
Text doesn't look like it's "behind" the subject at all. That illusion is entirely dependent on your Foreground (RGBA) cutout actually having accurate alpha around the subject's silhouette. If the cutout's edges are sloppy or the alpha is binary instead of a clean matte, the text will look like it's just sitting under a rough stencil rather than genuinely occluded by the subject. The quality of your background-removal step upstream is doing most of the visual work here, not this node.
Text bleeds through where it shouldn't, or doesn't show where it should. Check the Text Mask itself before touching opacity - a mask that's inverted or doesn't tightly match the Text Image will place text in the wrong regions regardless of what opacity values you set.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| Background | IMAGE | — | |
| Text Image | IMAGE | — | |
| Text Mask | MASK | — | |
| Foreground (RGBA) | IMAGE | — | |
| Foreground Opacity | FLOAT | 1.000–1 | — |
| Text Image Opacity | FLOAT | 1.000–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |