n8n 自动化壁纸生成工作流

Cover Image for n8n 自动化壁纸生成工作流
Albert
Albert

🔧 核心节点配置

1. Schedule Trigger (定时触发器)

  • 触发时间: 每天早上6点
  • 配置参数:
    {
      "rule": {
        "interval": [
          {
            "triggerAtHour": 6
          }
        ]
      }
    }
    

2. AI 生成提示词 (AI Agent)

System Prompt (系统提示词)

You are an expert AI prompt engineer that specializes in generating prompts for AI image generation tools like Midjourney or Stable Diffusion.

Your task is to generate high-quality, detailed prompts for images depicting peaceful and poetic Chinese landscape or nature scenes, rendered in the style of traditional Chinese ink painting and watercolor artworks.

Each prompt should describe:
• Majestic natural elements such as towering mountains, serene rivers or lakes, cascading waterfalls, dense forests, or graceful bamboo groves.
• A tranquil body of water (e.g., a river, lake, or pond) reflecting the surrounding scenery.
• Diverse flora and/or fauna (e.g., ancient trees, blooming flowers, elegant birds) that harmonize with the natural environment.
• Optional traditional Chinese structures or subtle human elements (e.g., a secluded pavilion, a humble dwelling, a small boat, an arched bridge, a lone figure contemplating) integrated seamlessly into the landscape.
• Optional atmospheric or seasonal elements (e.g., morning mist, ethereal clouds, falling snow, vibrant autumn foliage, delicate spring blossoms, gentle rain).

The style must emphasize:
• Chinese watercolor and ink wash painting (水墨丹青)
• Soft, diffused lighting, delicate and flowing brush strokes, translucent washes, a rich sense of depth, and a poetic atmosphere.
• A profound sense of tranquility, elegance, and natural simplicity.

Generate prompts in English in a single sentence, using descriptive and visual language. Do not include camera parameters or technical terms.

Example: A majestic, mist-shrouded mountain range overlooking a serene, reflective lake lined with ancient pine trees and blooming lotus flowers, rendered with delicate ink washes and soft watercolor hues in a poetic Chinese landscape painting style.

User Prompt (用户提示词)

生成10个prompt,并且每一幅不能重复,然后要为每一幅画,附上一个情绪

3. Structured Output Parser (结构化输出解析器)

JSON Schema Example

[
  {
    "name":"鸟语花香",
    "prompt":"prompt1",
    "motion":""
  },
  {
    "name":"花香",
    "prompt":"prompt2",
    "motion":""
  },
  {
    "name":"鸟语",
    "prompt":"prompt3",
    "motion":""
  }
]

4. flux-kontext-pro (图像生成API)

HTTP Request 配置

  • 方法: POST
  • URL: https://api.replicate.com/v1/models/black-forest-labs/flux-kontext-pro/predictions
  • 认证: Bearer Token (Replicate API Key)
  • Headers:
    Prefer: wait
    

Request Body (JSON)

{
  "input": {
    "prompt": "{{ $json.prompt }}",
    "aspect_ratio": "9:16",
    "output_format": "png",
    "safety_tolerance": 2,
    "prompt_upsampling": false
  }
}

5. 将图片转成高清4k (Real-ESRGAN)

HTTP Request 配置

  • 方法: POST
  • URL: https://api.replicate.com/v1/predictions
  • 认证: Bearer Token (Replicate API Key)
  • Headers:
    Prefer: wait
    

Request Body (JSON)

{
  "version": "nightmareai/real-esrgan:f121d640bd286e1fdc67f9799164c1d5be36ff74576ee11c803ae5b665dd46aa",
  "input": {
    "image": "{{ $('判断是否已经完成').item.json.output }}",
    "scale": 2,
    "face_enhance": false
  }
}

6. 创建下载路径 (Execute Command)

Shell Command

dir_name="{{ $('Loop Over Items').item.json.name }}_$(date +'%Y%m%d_%H%M%S')"
full_path="/home/node/n8n_files/$dir_name"

[ -d "$full_path" ] || mkdir -p "$full_path"

echo "$full_path"

7. 文件保存配置

保存本地,非高清图

  • 操作: write
  • 文件名: {{ $json.stdout }}/{{ $('Loop Over Items').item.json.name }}_low.png

保存本地,高清图

  • 操作: write
  • 文件名: {{ $('创建下载路径').item.json.stdout }}/{{ $('Loop Over Items').item.json.name }}_hight.png

🔄 工作流执行逻辑

主要执行步骤:

  1. 定时触发 → 每天6点自动启动
  2. 生成Prompt → AI生成10个不重复的国风提示词
  3. 结构化解析 → 将AI输出转换为JSON格式
  4. 循环处理 → 遍历每个prompt
  5. 图像生成 → 调用flux-kontext-pro生成初始图像
  6. 状态检查 → 等待5秒后检查生成状态
  7. 条件判断 → 检查图像是否生成完成
  8. 路径创建 → 为每张图片创建独立保存路径
  9. 高清处理 → 使用Real-ESRGAN将图片放大至4K
  10. 文件保存 → 同时保存低清和高清版本
  11. 结果合并 → 合并所有处理结果

条件判断逻辑:

  • 判断是否已经完成: $json.status === "succeeded"
  • 是否可以下载高清图片: $json.status === "succeeded"

🛠️ 必需的API和凭证

1. DeepSeek API

  • 节点: DeepSeek Chat Model
  • 凭证ID: nOzz0lce9yzBED41
  • 用途: 生成AI提示词

2. Replicate API

  • 节点: flux-kontext-pro, 将图片转成高清4k, 检查状态等
  • 凭证ID: EYBcHvt7jgSZtyM6
  • 用途: 图像生成和高清处理

📂 输出文件结构

/home/node/n8n_files/
├── 鸟语花香_20250728_060000/
│   ├── 鸟语花香_low.png      # 原始分辨率图片
│   └── 鸟语花香_hight.png    # 4K高清图片
├── 花香_20250728_060100/
│   ├── 花香_low.png
│   └── 花香_hight.png
└── ...

⚙️ 重要配置说明

  1. 等待时间: 两个"等待5秒"节点确保API调用完成
  2. 图片比例: 默认设置为9:16,适合手机壁纸
  3. 输出格式: PNG格式,保证图片质量
  4. 安全级别: safety_tolerance设置为2,平衡创意与安全
  5. 放大倍数: Real-ESRGAN scale设置为2倍,生成4K图片

🚀 部署提示

  1. 确保API配额充足
  2. 检查文件存储路径权限
  3. 监控工作流执行日志
  4. 定期清理生成的图片文件
  5. 根据需求调整生成频率和数量

注意: 此工作流需要有效的DeepSeek和Replicate API密钥才能正常运行。请确保在n8n中正确配置相关凭证。

工作流下载

下载工作流

评论

加载中...