8
n8n 中文网amn8n.com

从WooCommerce产品图片中移除背景

中级

这是一个Design, AI领域的自动化工作流,包含 12 个节点。主要使用 Ftp, Set, Code, HttpRequest, WooCommerce 等节点,结合人工智能技术实现智能自动化。 使用API和Google Sheet自动化WooCommerce产品图片背景移除

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "jDO3Mna9FMs6rTdJ",
  "meta": {
    "instanceId": "a4bfc93e975ca233ac45ed7c9227d84cf5a2329310525917adaf3312e10d5462",
    "templateCredsSetupCompleted": true
  },
  "name": "从 WooCommerce 产品图片中移除背景",
  "tags": [],
  "nodes": [
    {
      "id": "7b97db40-96b7-4f7d-a26f-14e2416d4730",
      "name": "当点击“执行工作流”时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -620,
        100
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "b1a25e04-37e1-425e-b146-090a8f49e43f",
      "name": "从图片 URL 移除",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        360,
        120
      ],
      "parameters": {
        "url": "https://api.backgroundcut.co/v2/cut/",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "image_file_url",
              "value": "={{ $json.image_url }}"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "id": "gzZbyF09CfhEOxUk",
          "name": "BackgroundCut API"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "383e0206-3cbe-4d4c-9e01-6ca857d3092b",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -620,
        -180
      ],
      "parameters": {
        "width": 720,
        "height": 180,
        "content": "## 预备步骤"
      },
      "typeVersion": 1
    },
    {
      "id": "0591f51b-4ac3-4613-b78f-8fcafd0a5893",
      "name": "FTP",
      "type": "n8n-nodes-base.ftp",
      "position": [
        920,
        120
      ],
      "parameters": {
        "path": "=/test/{{ $json.fileName }}",
        "operation": "upload"
      },
      "credentials": {
        "ftp": {
          "id": "LHpoBQkf0LTumonL",
          "name": "FTP BunnyCDN"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ca4a2fd6-cf8d-4dac-860d-f890ed482029",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -180,
        100
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "cbcb21e3-9d5c-482f-b630-6fb693a32491",
      "name": "获取文件名",
      "type": "n8n-nodes-base.code",
      "position": [
        640,
        120
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'fileName' to the JSON of each one\nfor (const item of $input.all()) {\n  const url = item.json.image_url;\n  const fileName = url.split('/').pop(); // Estrae l'ultima parte dell'URL\n  item.json.fileName = fileName;\n}\n\nreturn $input.all();\n"
      },
      "typeVersion": 2
    },
    {
      "id": "0604040e-b6bb-444c-ba17-3b776a388826",
      "name": "新图片 URL",
      "type": "n8n-nodes-base.set",
      "position": [
        360,
        380
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0a6e53bf-3d3d-42b3-a08f-b7d2329a987b",
              "name": "image_url",
              "type": "string",
              "value": "=https://YOUR_FTP_URL/{{ $json.fileName }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d3fd2786-7218-4b60-a287-3fdf5621df0a",
      "name": "更新产品",
      "type": "n8n-nodes-base.wooCommerce",
      "position": [
        640,
        380
      ],
      "parameters": {
        "imagesUi": {
          "imagesValues": [
            {
              "alt": "",
              "src": "={{ $json.image_url }}",
              "name": ""
            }
          ]
        },
        "resource": "product",
        "operation": "update",
        "productId": "={{ $('Set Product Fields').item.json.ID }}",
        "metadataUi": {},
        "dimensionsUi": {},
        "updateFields": {}
      },
      "credentials": {
        "wooCommerceApi": {
          "id": "vYYrjB5kgHQ0XByZ",
          "name": "WooCommerce (wp.test.7hype.com)"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4b5b75d1-2d7b-418b-938a-4f75c0ed84ea",
      "name": "设置产品字段",
      "type": "n8n-nodes-base.set",
      "position": [
        100,
        120
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7510c8a8-77e4-4985-a83e-eb313c8b3da9",
              "name": "image_url",
              "type": "string",
              "value": "={{ $json.IMAGE }}"
            },
            {
              "id": "ed48e2f6-8423-4317-a746-b6dfa22c7f7c",
              "name": "product_id",
              "type": "string",
              "value": "={{ $json.ID }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "a5056024-b941-4078-a859-8e83dc0a28a5",
      "name": "获取产品",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -400,
        100
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "DONE"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DxiZTvam_4oHHnZVBj_3K3pmWRld8T7l2v_DMuGsqss/edit#gid=0",
          "cachedResultName": "Foglio1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1DxiZTvam_4oHHnZVBj_3K3pmWRld8T7l2v_DMuGsqss",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DxiZTvam_4oHHnZVBj_3K3pmWRld8T7l2v_DMuGsqss/edit?usp=drivesdk",
          "cachedResultName": "BackgroundCut WooCommerce products"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "JYR6a64Qecd6t8Hb",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "badead5e-2ce6-4b21-a859-ebc6af0110ae",
      "name": "更新表格",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        920,
        380
      ],
      "parameters": {
        "columns": {
          "value": {
            "DONE": "x",
            "NEW IMAGE": "={{ $('New Image Url').item.json.image_url }}",
            "row_number": "={{ $('Set Product Fields').item.json.row_number }}"
          },
          "schema": [
            {
              "id": "ID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "IMAGE",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "IMAGE",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "NEW IMAGE",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "NEW IMAGE",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "DONE",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "DONE",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DxiZTvam_4oHHnZVBj_3K3pmWRld8T7l2v_DMuGsqss/edit#gid=0",
          "cachedResultName": "Foglio1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1DxiZTvam_4oHHnZVBj_3K3pmWRld8T7l2v_DMuGsqss",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DxiZTvam_4oHHnZVBj_3K3pmWRld8T7l2v_DMuGsqss/edit?usp=drivesdk",
          "cachedResultName": "BackgroundCut WooCommerce products"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "JYR6a64Qecd6t8Hb",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "b7752651-e5b0-4202-9647-c68dc86ffaa3",
      "name": "便签 7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -620,
        -480
      ],
      "parameters": {
        "color": 3,
        "width": 720,
        "height": 260,
        "content": "# 从 WooCommerce 产品图片中移除背景"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d8ae8235-9079-4d57-9999-24cde0c4ca77",
  "connections": {
    "FTP": {
      "main": [
        [
          {
            "node": "New Image Url",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ger Products": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Filename": {
      "main": [
        [
          {
            "node": "FTP",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Sheet": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New Image Url": {
      "main": [
        [
          {
            "node": "Update product",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update product": {
      "main": [
        [
          {
            "node": "Update Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Set Product Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Product Fields": {
      "main": [
        [
          {
            "node": "Remove from Image URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove from Image URL": {
      "main": [
        [
          {
            "node": "Get Filename",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Ger Products",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 设计, 人工智能

需要付费吗?

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

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

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

作者

Full-stack Web Developer based in Italy specialising in Marketing & AI-powered automations. For business enquiries, send me an email at info@n3w.it or add me on Linkedin.com/in/davideboizza

外部链接
在 n8n.io 查看

分享此工作流