8
n8n 中文网amn8n.com

使用OpenAI的GPT-Image-1模型生成和编辑图像

中级

这是一个Design, AI领域的自动化工作流,包含 11 个节点。主要使用 HttpRequest, ConvertToFile, ManualTrigger 等节点,结合人工智能技术实现智能自动化。 使用OpenAI的GPT-Image-1模型生成和编辑图像

前置要求
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "96b96d0aa1e4ff5d5b6779332b149e3ef3364191562d79083d0309cf3ddfa53e"
  },
  "nodes": [
    {
      "id": "0e78a29e-87ba-4665-84c1-a413c45e25dc",
      "name": "当点击“测试工作流”时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -420,
        -40
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "fe7b054a-e0c9-4642-a97f-6bec60a1ec55",
      "name": "编辑图片(OpenAI)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        500,
        -40
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/images/edits",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "image",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            },
            {
              "name": "prompt",
              "value": "add a mask with horns"
            },
            {
              "name": "model",
              "value": "gpt-image-1"
            },
            {
              "name": "n",
              "value": "1"
            },
            {
              "name": "size",
              "value": "1024x1024"
            },
            {
              "name": "quality",
              "value": "high"
            }
          ]
        },
        "nodeCredentialType": "openAiApi"
      },
      "credentials": {
        "openAiApi": {
          "id": "JyI0PkPec1FrpMkt",
          "name": "OpenAi AIFB account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1e1df05c-d8f9-4033-87ee-70be344ab961",
      "name": "创建图片调用",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -120,
        -40
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/images/generations",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "gpt-image-1"
            },
            {
              "name": "prompt",
              "value": "A cute red panda like dark super hero"
            },
            {
              "name": "n",
              "value": "={{Number(1)}}"
            },
            {
              "name": "size",
              "value": "1024x1024"
            },
            {
              "name": "moderation",
              "value": "low"
            },
            {
              "name": "background",
              "value": "auto"
            }
          ]
        },
        "nodeCredentialType": "openAiApi"
      },
      "credentials": {
        "openAiApi": {
          "id": "JyI0PkPec1FrpMkt",
          "name": "OpenAi AIFB account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "4c44da91-0d12-4e7f-bc89-5accddd837d7",
      "name": "将JSON二进制转换为文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        200,
        -40
      ],
      "parameters": {
        "options": {
          "fileName": "name_example",
          "mimeType": "image/png"
        },
        "operation": "toBinary",
        "sourceProperty": "data[0].b64_json"
      },
      "typeVersion": 1.1
    },
    {
      "id": "3b8936b7-f0a2-4776-b10a-f06ceb9af31d",
      "name": "将JSON二进制转换为最终文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        820,
        -40
      ],
      "parameters": {
        "options": {
          "fileName": "",
          "mimeType": "image/png"
        },
        "operation": "toBinary",
        "sourceProperty": "data[0].b64_json"
      },
      "typeVersion": 1.1
    },
    {
      "id": "3d3238d5-6040-4b74-8e6a-9e1e64198099",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        -200
      ],
      "parameters": {
        "height": 320,
        "content": "### 🧪 手动触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "c3378100-f688-4199-a038-83b9220afa91",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -200,
        -320
      ],
      "parameters": {
        "color": 3,
        "width": 280,
        "height": 440,
        "content": "### 🎨 图片生成(OpenAI)"
      },
      "typeVersion": 1
    },
    {
      "id": "82a880de-74de-44e5-8448-f487c9376d0e",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        100,
        -200
      ],
      "parameters": {
        "color": 5,
        "width": 280,
        "height": 320,
        "content": "### 🧾 将base64转换为文件"
      },
      "typeVersion": 1
    },
    {
      "id": "42ccb29f-b820-4791-9683-4eb0f00ff2d3",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -320
      ],
      "parameters": {
        "color": 3,
        "width": 280,
        "height": 440,
        "content": "### ✏️ 图片编辑(OpenAI)"
      },
      "typeVersion": 1
    },
    {
      "id": "4c8846ab-b3f2-4c7c-9283-5a40a55b816d",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        740,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 280,
        "height": 360,
        "content": "### 🧾 最终转换(base64 → 文件)"
      },
      "typeVersion": 1
    },
    {
      "id": "2b2533f8-b7aa-4499-970e-9b0546b73c0e",
      "name": "便利贴5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1240,
        -860
      ],
      "parameters": {
        "color": 6,
        "width": 700,
        "height": 980,
        "content": "## 🧠 图片AI工作流概述"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Create image call": {
      "main": [
        [
          {
            "node": "Convert json binary to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Image (OpenAI)": {
      "main": [
        [
          {
            "node": "Convert json binary to File final",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert json binary to File": {
      "main": [
        [
          {
            "node": "Edit Image (OpenAI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Create image call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 设计, 人工智能

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量11
分类2
节点类型4
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Edoardo Guzzi

Edoardo Guzzi

@mredodos

Automation expert with 10+ years in programming, AI, Chrome extensions, and mobile apps. Specializing in PHP, JS, and Python, I design custom n8n workflows to streamline processes and boost productivity. Explore my templates or contact me for tailored solutions.

外部链接
在 n8n.io 查看

分享此工作流