文生图工作流

文生图(Text-to-Image)是最基础的ComfyUI工作流,通过文本提示词生成图像。

工作流概述

工作流信息

功能特点

适用场景

工作流结构

文生图工作流示意图

下图展示了完整的文生图工作流流程:

这个图展示了文生图工作流的完整流程: - 模型加载: CheckpointLoaderSimple加载主模型 - 文本编码: CLIPTextEncode编码提示词 - 潜在空间: EmptyLatentImage创建初始噪声 - 采样生成: KSampler执行去噪生成 - 解码输出: VAEDecode解码为图像 - 保存结果: SaveImage保存最终图像

节点流程图

CheckpointLoaderSimple
├── MODEL ──────────────┐
├── CLIP ───┬────────────┼── KSampler ─── VAEDecode ─── SaveImage
└── VAE ────┴────────────┘               │
                                          └── samples ──┘

CLIPTextEncode (positive) ─── positive ──┘
CLIPTextEncode (negative) ─── negative ──┘

EmptyLatentImage ─── latent_image ───────┘

核心节点说明

使用步骤

步骤1: 准备工作

  1. 确保已安装ComfyUI
  2. 下载Stable Diffusion模型文件
  3. 将模型放入 models/checkpoints/ 目录

步骤2: 加载工作流

  1. 打开ComfyUI
  2. 点击"Load"按钮
  3. 选择工作流JSON文件

步骤3: 配置参数

ckpt_name: v1-5-pruned-emaonly.ckpt
text: beautiful landscape, mountains, sunset, 4k, detailed, cinematic lighting
text: ugly, blurry, low quality, distorted, bad anatomy
width: 512
height: 512
batch_size: 1
seed: 123456789 (或点击随机按钮)
steps: 20
cfg: 8
sampler_name: euler
scheduler: normal
denoise: 1.0
filename_prefix: txt2img_

步骤4: 执行工作流

  1. 点击"Queue Prompt"按钮
  2. 等待执行完成
  3. 查看生成的图像

工作流JSON

{
  "3": {
    "inputs": {
      "seed": 123456789,
      "steps": 20,
      "cfg": 8,
      "sampler_name": "euler",
      "scheduler": "normal",
      "denoise": 1,
      "model": ["4", 0],
      "positive": ["6", 0],
      "negative": ["7", 0],
      "latent_image": ["5", 0]
    },
    "class_type": "KSampler"
  },
  "4": {
    "inputs": {
      "ckpt_name": "v1-5-pruned-emaonly.ckpt"
    },
    "class_type": "CheckpointLoaderSimple"
  },
  "5": {
    "inputs": {
      "width": 512,
      "height": 512,
      "batch_size": 1
    },
    "class_type": "EmptyLatentImage"
  },
  "6": {
    "inputs": {
      "text": "beautiful landscape, mountains, sunset, 4k, detailed, cinematic lighting",
      "clip": ["4", 1]
    },
    "class_type": "CLIPTextEncode"
  },
  "7": {
    "inputs": {
      "text": "ugly, blurry, low quality, distorted, bad anatomy",
      "clip": ["4", 1]
    },
    "class_type": "CLIPTextEncode"
  },
  "8": {
    "inputs": {
      "samples": ["3", 0],
      "vae": ["4", 2]
    },
    "class_type": "VAEDecode"
  },
  "9": {
    "inputs": {
      "filename_prefix": "txt2img_",
      "images": ["8", 0]
    },
    "class_type": "SaveImage"
  }
}

参数配置指南

关键参数说明

示例结果

示例1: 风景

示例2: 肖像

示例3: 动漫风格

提示词工程

正向提示词技巧

  1. 描述主体: 清晰描述主要对象
  2. 添加细节: 添加细节和修饰词
  3. 指定风格: 指定艺术风格
  4. 质量关键词: 添加高质量关键词

负向提示词技巧

  1. 避免低质量: 添加低质量关键词
  2. 避免不想要的内容: 明确避免的内容
  3. 避免特定风格: 如果不想要某种风格

提示词示例

正向: majestic mountain range, snow-capped peaks, golden hour light, dramatic clouds, ultra detailed, 8k, photorealistic
负向: blurry, low quality, ugly, distorted, oversaturated
正向: professional portrait, beautiful woman, detailed eyes, soft lighting, high quality, sharp focus, 8k
负向: ugly, distorted, bad anatomy, blurry, low resolution, cartoonish
正向: abstract art, vibrant colors, geometric shapes, dynamic composition, modern art style, high detail
负向: realistic, photo, boring, simple, low contrast

优化建议

性能优化

质量优化

批量生成

常见问题

Q1: 生成的图像质量差怎么办?

A: 增加steps,调整cfg,改进提示词,使用更好的采样器。

Q2: 如何生成不同风格的图像?

A: 在提示词中添加风格关键词,如"anime style", "photorealistic"等。

Q3: 如何提高生成速度?

A: 减少steps,使用快速采样器,降低分辨率。

Q4: 如何批量生成图像?

A: 增加batch_size参数,或使用不同的seed多次执行。

Q5: 提示词如何写更好?

A: 清晰描述主体,添加细节,指定风格,使用质量关键词。

变体工作流

变体1: 高质量文生图

变体2: 快速文生图

变体3: 批量文生图

相关工作流

扩展阅读

更新日志