Nodes/ComfyUI-Html2Image/🐟Template To Image
ComfyUI Node

🐟Template To Image

Type a few text fields, get a finished poster — real HTML rendered by real Chrome

By liuqianhonga·Created 2 years ago·Updated about a year ago· 16
🐟Template To Image
  • image1
  • image2
  • image3
  • image
  • width
  • height
template_filetemplates/jieqi/template.html
width1242
height2208
wait_time_seconds0.50
text1
text2
text3
text4
text5
text6
text7

This is the node people actually come to this pack for. Feed it a background image and a handful of text strings, and out the other end you get a fully typeset poster as a real ComfyUI IMAGE tensor - no PIL fiddling, no compositing nodes, no fighting with fonts. The pack's README leans hard on this one, and it shows: it's got a whole workflow image for it.

The trick is that the layout is done in actual HTML and CSS, by a designer, not by you. TemplateToImage is the "turn text boxes into a rendered design" node that ComfyUI is otherwise missing. If you've ever wanted to automate greeting cards, event posters, or those Chinese solar-term (节气) share images, this is the fastest path. You wire the output straight into a Save Image node, or VAE-encode it if you want to feed the rendered design back into the diffusion loop.

How it works

Under the hood it's the pack's shared Selenium base: the node takes a Jinja2 HTML template, stuffs your text and images into it, writes the rendered page to a temporary HTML file next to the template, and screenshots it with headless Chrome at your chosen width and height. The IMAGE you get is a screenshot of a real browser rendering - that's why the typography, kerning, and gradients all look right.

One thing to know: images you pass in get saved as imageN.png inside the pack's template folder so the HTML can reference them, then deleted after the screenshot. That means the pack directory needs write permission, and it's why a background image sometimes doesn't show up on a read-only install.

The inputs that matter

  • template_file - pick your design: templates/jieqi/template.html (the solar-term poster) or templates/happy_new_year/template.html (the bilingual new-year card). That's the whole template library, so far.
  • width / height - default 1242×2208, the jieqi template's native poster size. Range is 64–4096.
  • wait_time_seconds - how long Chrome waits before shooting, default 0.5.

The text1text7 and image1image3 slots mean different things per template. For jieqi: text1 is the big vertical title, text2 the date line, text3 the blessing, and text4 is the dark overlay's opacity (a number like 0.3). image1 is the background photo. For happy_new_year: text1 logo, text2 domain, text3/text4 the English and Chinese greetings, text5/text6 the two bottom lines, text7 the big "HAPPY NEW YEAR", and image2 is a QR code.

Watch for this: the README says happy_new_year takes eight text fields, but the node actually exposes seven. The template reads an eighth value (its overlay opacity) that you can't reach from the UI, so that one keeps its default 0.3. Minor, but it'll save you a confused five minutes.

Outputs

image (the rendered IMAGE), plus width and height as INTs. Those last two are handy - plug them into an EmptyLatent or a conditioning size so downstream nodes match the poster exactly.

Installing

Via ComfyUI Manager, search "ComfyUI-Html2Image". Or manually:

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

Then restart ComfyUI. Dependencies are selenium, webdriver_manager, jinja2, and Pillow (torch and numpy are already there). The one dependency nobody tells you about: you need Google Chrome installed on the machine. Selenium launches a real Chrome binary - ChromeDriverManager only fetches the driver, not the browser. The README doesn't mention this, and it's the #1 way this pack fails on a fresh box.

Troubleshooting

  • First run is slow - webdriver_manager downloads chromedriver once. Needs internet.
  • White/blank output - the template rendered but nothing painted; usually a missing relative asset or a typo in template_file.
  • Background image missing - the node wrote image1.png into the pack folder and couldn't; check write permission on ComfyUI/custom_nodes/ComfyUI-Html2Image.
  • "SessionNotCreated" / no such binary - Chrome isn't installed. Install Chromium/Chrome and retry.

It's a narrow tool, but for "generate a finished poster from text fields" it's the smoothest thing in the pack.

Categoryimage

Inputs (14)

NameTypeDefaultDescription
template_fileSTRINGtemplates/jieqi/template.html
widthINT124264–4096
heightINT220864–4096
wait_time_secondsFLOAT0.50
text1optSTRING
text2optSTRING
text3optSTRING
text4optSTRING
text5optSTRING
text6optSTRING
text7optSTRING
image1optIMAGE
image2optIMAGE
image3optIMAGE

Outputs (3)

NameTypeDescription
imageIMAGE
widthINT
heightINT