ComfyUI进行海报创作
现在的AI文生图已经可以生成质量很高的图片,最近我也尝试了一下用ComfyUI结合文生图模型来创作海报,在英伟达服务器上搭建了一个ComfyUI服务,开放给企业内部人员进行海报创作。
首先是安装ComfyUI,可以通过以下命令复制代码
git clone git@github.com:comfyanonymous/ComfyUI.git
然后在comfyui的目录下执行命令安装依赖包
pip install -r requirements.txt
最后执行命令启动,因为要开放给企业内部使用,所以设定端口和开放所有连接。
python main.py --port 8888 --listen 0.0.0.0
在浏览器中打开ComfyUI的地址和端口,然后选择菜单栏的工作流->浏览模板,选择Flux里面的Flux Dev的检查点示例,如以下截图:
工作流界面如下:
这个工作流由多个节点组成,最开始的节点是加载Flux模型的Checkpoint文件,默认是加载flux1-dev-fp8.safetensors,可以在Comfy-Org/flux1-dev · HF Mirror下载模型权重文件。下载完成后,我在ComfyUI的models/checkpoints目录下创建一个软链接,指向这个模型权重文件。
Checkpoint加载器节点的CLIP属性是连接了两个Clip Text Encode节点,分别对应正向提示词和反向提示词,对于FLUX来说不需要反向提示词,因此这里我们只需要输入英语的正向提示词即可。正向提示词的输出通过Flux引导节点连接到K采样器的正面条件属性。
Checkpoint加载器节点的模型属性是连接到K采样器节点模型属性,空Latent图像节点用于设置生成图像的分辨率以及一批次里面同时生成多少张图片,这个可以基于显卡的显存来调整。
K采样器可以对生成图像的质量和随机性进行控制,调整步数为更高的值可以提高质量,当然也需要花费更多的时间,最后输出Latent连接到VAE解码节点。
VAE解码节点是把隐向量解码为图像的作用,其接收K采样器输出的Latent向量,结合Checkpoint加载器的VAE模型输出,对图像解码后输出。
下面我们要生成一张和端午节相关的海报,我直接利用DeepSeek来帮我生成提示词,例如我问DeepSeek,“我想通过文生图模型Flux来制作一个端午节的海报,需要有粽子,龙舟这些元素,海报风格是传统风格,请用英语给我写一段提示词”, 然后DeepSeek生成的英语提示词如下:
An ornate traditional Chinese festival poster in 8K resolution, featuring:
1.Dragon Boat Scene: A majestic wooden dragon boat with intricate carvings sails through emerald-green river waves. Rowers in ancient Hanfu costumes paddle rhythmically, their headbands fluttering in the wind.
2.Zongzi Presentation: Bamboo-leaf wrapped pyramid zongzi with visible glutinous rice textures, arranged on a vintage wooden tray beside a celadon teacup. Golden rice grains spill artistically from one partially unwrapped zongzi.
3.Cultural Symbols:
Qu Yuan's silhouette reciting poetry against mountain-shaped 《楚辞》calligraphy scrolls
Five-colored silk threads twisting into auspicious cloud patterns
Calamus and artemisia branches framing the composition
4.Color Palette: Dominant emerald green (bamboo leaves) and vermilion red (dragon boat accents) with gold foil detailing. Background using ink-wash gradient from celadon to rice paper beige.
5.Typography: Central title '端午安康' in bold seal script with bronze texture, English subtitle 'Dragon Boat Festival' using Song Dynasty-style typography. Decorative borders combining dragon scale patterns and auspicious cloud motifs.
6.Lighting & Texture: Soft sunlight casting dragon boat shadows on rice paper texture, subtle silk fabric grain overlay, antique bronze oxidation effects on metal elements
直接把这段提示词复制到Clip Text Encode节点,然后点击运行,以下是FLUX工作流生成的几张海报图片。
![]() | ![]() |
![]() | ![]() |
从生成的图片来看,图片的质量还是挺不错的,提示词里面提到的元素也都有展现,美中不足的是对于汉字的生成不理想,虽然字体挺好看,但是字都是错的。
如果要修改海报里面的文字,有两种方法,一种是用Photoshop等进行后续处理。另一种是基于AI来生成文字,例如可以基于阿里的AnyText模型,配合ComfyUI来进行生成。
下面介绍一下基于AnyText来生成文字。
进入到ComfyUI的custom_nodes目录,然后执行命令
git clone https://github.com/zmwv823/ComfyUI_Anytext.git
Anytext有1.1和2.0版本两个模型,可以从zmwv823/AnyText_control_model · HF Mirror和zmwv823/AnyText2_control_model · HF Mirror下载,下载后的模型同样是在checkpoints目录下建立软链接。
另外还需要用到字体可以在以下github代码库中的font目录找到,将其复制到ComfyUI的models/font目录下tyxsspa/AnyText2: Official implementation code of the paper <AnyText2: Visual Text Generation and Editing With Customizable Attributes>
这个工作流插件有一个工作流例子,但是在我本地跑会报错,我主要用到的是Text edit的功能,因此我稍微修改了一下,修改后的工作流如下:
{"id": "fec4a5bd-9e99-42b7-b906-07af85fa3fdb","revision": 0,"last_node_id": 143,"last_link_id": 3441,"nodes": [{"id": 14,"type": "EmptyLatentImage","pos": [-2320.037841796875,1267.0440673828125],"size": [210,106],"flags": {},"order": 0,"mode": 0,"inputs": [],"outputs": [{"name": "LATENT","type": "LATENT","slot_index": 0,"links": [3412]}],"properties": {"Node name for S&R": "EmptyLatentImage","cnr_id": "comfy-core","ver": "0.3.24"},"widgets_values": [768,512,1]},{"id": 88,"type": "VAEDecode","pos": [-805.5465087890625,683.2332153320312],"size": [210,46],"flags": {},"order": 8,"mode": 0,"inputs": [{"name": "samples","type": "LATENT","link": 3372},{"name": "vae","type": "VAE","link": 3383}],"outputs": [{"name": "IMAGE","type": "IMAGE","slot_index": 0,"links": [3437]}],"properties": {"Node name for S&R": "VAEDecode","cnr_id": "comfy-core","ver": "0.3.24"},"widgets_values": []},{"id": 129,"type": "UL_AnyTextLoader","pos": [-2400.03759765625,657.0445556640625],"size": [315,194],"flags": {},"order": 1,"mode": 0,"showAdvanced": true,"inputs": [],"outputs": [{"name": "model","type": "AnyText_Model","links": [3439]},{"name": "vae","type": "VAE","slot_index": 1,"links": [3383]},{"name": "ckpt_name","type": "STRING","links": null}],"properties": {"Node name for S&R": "UL_AnyTextLoader","cnr_id": "anytext","ver": "46c5b26db04a195ca2e910f45124d8584ec5151e"},"widgets_values": ["Counterfeit-V3.0_fix_fp16.safetensors","control_sd15_anytext_v2.0.safetensors","None","fp16","auto"]},{"id": 142,"type": "SaveImage","pos": [-807.19677734375,816.7080688476562],"size": [270,270],"flags": {},"order": 9,"mode": 0,"inputs": [{"name": "images","type": "IMAGE","link": 3437}],"outputs": [],"properties": {},"widgets_values": ["ComfyUI"]},{"id": 140,"type": "LoadImage","pos": [-2400.03759765625,907.0445556640625],"size": [315,314],"flags": {},"order": 2,"mode": 0,"inputs": [],"outputs": [{"name": "IMAGE","type": "IMAGE","links": [3428]},{"name": "MASK","type": "MASK","links": [3430]}],"properties": {"Node name for S&R": "LoadImage","cnr_id": "comfy-core","ver": "0.3.26"},"widgets_values": ["clipspace/clipspace-mask-77115.30000001192.png [input]","image"]},{"id": 126,"type": "UL_AnyTextSampler","pos": [-1171.55810546875,589.9530029296875],"size": [330,720],"flags": {},"order": 7,"mode": 0,"inputs": [{"name": "model","type": "AnyText_Model","link": 3441},{"name": "positive","type": "CONDITIONING","link": 3416},{"name": "negative","type": "CONDITIONING","link": 3417}],"outputs": [{"name": "latent","type": "LATENT","slot_index": 0,"links": [3372]}],"properties": {"Node name for S&R": "UL_AnyTextSampler","cnr_id": "anytext","ver": "46c5b26db04a195ca2e910f45124d8584ec5151e"},"widgets_values": [707394087536006,"fixed",20,3,1,1,0,true,true]},{"id": 138,"type": "UL_AnyTextEncoder","pos": [-1604.63623046875,867.7891845703125],"size": [400,500],"flags": {},"order": 6,"mode": 0,"inputs": [{"name": "model","type": "AnyText_Model","link": 3440},{"name": "mask","type": "MASK","link": 3430},{"name": "prompt","type": "STRING","link": 3415},{"name": "texts","type": "LIST","link": 3411},{"name": "latent","type": "LATENT","link": 3412},{"name": "image","shape": 7,"type": "IMAGE","link": 3428},{"name": "fonts","shape": 7,"type": "ANYTEXT_FONTS","link": 3438}],"outputs": [{"name": "positive","type": "CONDITIONING","links": [3416]},{"name": "negative","type": "CONDITIONING","links": [3417]}],"properties": {"Node name for S&R": "UL_AnyTextEncoder","cnr_id": "anytext","ver": "a40aaf7c21d91c1d44a20be3b3dc4dd4984e1ad9"},"widgets_values": ["Arial_Unicode.ttf",false,true,"best quality, extremely detailed,4k, HD, supper legible text, clear text edges, clear strokes, neat writing, no watermarks","low-res, bad anatomy, extra digit, fewer digits, cropped, worst quality, low quality, watermark, unreadable text, messy words, distorted text, disorganized writing, advertising picture",false,false,true,false]},{"id": 143,"type": "U_LoRAS","pos": [-1960.242919921875,1091.8482666015625],"size": [270,414],"flags": {},"order": 5,"mode": 0,"inputs": [{"name": "model","type": "AnyText_Model","link": 3439}],"outputs": [{"name": "model","type": "AnyText_Model","links": [3440,3441]},{"name": "path","type": "STRING","links": null}],"properties": {"Node name for S&R": "U_LoRAS"},"widgets_values": ["retrocgi_sd15_v1.safetensors",1,false,"retrocgi_sd15_v1.safetensors",1,false,"retrocgi_sd15_v1.safetensors",1,false,"retrocgi_sd15_v1.safetensors",1,false,"retrocgi_sd15_v1.safetensors",1,false]},{"id": 91,"type": "UL_AnyTextFormatter","pos": [-1609.169677734375,615.0557861328125],"size": [400,200],"flags": {},"order": 3,"mode": 0,"inputs": [],"outputs": [{"name": "prompt","type": "STRING","links": [3415]},{"name": "texts","type": "LIST","links": [3411]}],"properties": {"Node name for S&R": "UL_AnyTextFormatter","cnr_id": "anytext","aux_id": "zmwv823/ComfyUI_Wrappers","ver": "53403db39dafafc90f0cdaaef4205a70e911136b"},"widgets_values": ["\"很萌\""]},{"id": 141,"type": "UL_AnyText2Fonts","pos": [-1965.430419921875,591.9107055664062],"size": [270,442],"flags": {},"order": 4,"mode": 0,"inputs": [],"outputs": [{"name": "fonts","type": "ANYTEXT_FONTS","links": [3438]}],"properties": {"Node name for S&R": "UL_AnyText2Fonts"},"widgets_values": [false,"黄引齐招牌体.ttf","pink","钉钉进步体.ttf","green","仿乾隆字体.ttf","blue","None","white","None","None","None","yellow","None","pink","None","gold"]}],"links": [[3372,126,0,88,0,"LATENT"],[3383,129,1,88,1,"VAE"],[3411,91,1,138,3,"LIST"],[3412,14,0,138,4,"LATENT"],[3415,91,0,138,2,"STRING"],[3416,138,0,126,1,"CONDITIONING"],[3417,138,1,126,2,"CONDITIONING"],[3428,140,0,138,5,"IMAGE"],[3430,140,1,138,1,"MASK"],[3437,88,0,142,0,"IMAGE"],[3438,141,0,138,6,"ANYTEXT_FONTS"],[3439,129,0,143,0,"AnyText_Model"],[3440,143,0,138,0,"AnyText_Model"],[3441,143,0,126,0,"AnyText_Model"]],"groups": [{"id": 5,"title": "Load","bounding": [-2410.03759765625,567.0445556640625,360,816.7999877929688],"color": "#3f789e","font_size": 22,"flags": {}},{"id": 9,"title": "Edit","bounding": [-1625.54736328125,543.233642578125,1120,820.7999877929688],"color": "#3f789e","font_size": 22,"flags": {}}],"config": {},"extra": {"ds": {"scale": 2.1113776745352832,"offset": [1149.1173323473379,-850.2762348670182]},"frontendVersion": "1.19.9","node_versions": {"ComfyUI_Wrappers": "ac4b6ff543cc4976960545dea78b7d4c4aed848d","comfy-core": "0.3.14","ComfyUI-Custom-Scripts": "a53ef9b617ed1331640d7a2cd97644995908dc00\n"},"VHS_latentpreview": false,"VHS_latentpreviewrate": 0,"VHS_MetadataImage": true,"VHS_KeepIntermediate": true},"version": 0.4
}
打开后的界面如下:
在加载图像节点,加载之前生成的图片,然后鼠标右键选择Open in MaskEditor,把需要修改的文字涂抹掉,选择需要的字体,在提示词节点写上我们需要的文字,然后点击运行即可。不过这个工作流运行的效果一般,生成的字体的质量不高。例如下图是重新生成字体后的海报: