AutomationFlowsWeb Scraping › Automatically Replace and Relight the Background of Any Image Using Apimage

Automatically Replace and Relight the Background of Any Image Using Apimage

ByGegenfeld @gegenfeld on n8n.io

This workflow takes an image URL and a description of the desired background, then uses the APImage AI API to produce a high-quality image, preserving the subject and applying a natural-looking new background.

Event trigger★★★☆☆ complexity10 nodesHTTP RequestForm TriggerGoogle Drive
Web Scraping Trigger: Event Nodes: 10 Complexity: ★★★☆☆ Added:

This workflow corresponds to n8n.io template #8619 — we link there as the canonical source.

This workflow follows the Form Trigger → Google Drive recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "id": "15ab6203-2c77-45ac-b5dd-79f404e090fa",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -140
      ],
      "parameters": {
        "width": 1220,
        "height": 300,
        "content": "\n\n##  \ud83e\udc6b How To Get Started \n\n1. Double-click the **APImage API** node to open it.\n2. Replace \"_YOUR_API_KEY_\" with your API Key.\n3. Use the **Replace Background** node to submit a request.\n\nNote: You can find your API Key inside the Dashboard of your APImage account. \n\n[Open the Dashboard \ud83e\udc65](https://apimage.org/dashboard) \n\nNeed support with your API key? \u2709 [ask@support.apimage.org](mailto:ask@support.apimage.org)"
      },
      "typeVersion": 1
    },
    {
      "id": "8cb25cf6-2de1-4a8a-b39f-dd3d277ef96e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        180
      ],
      "parameters": {
        "color": 4,
        "width": 300,
        "height": 1160,
        "content": "### Output Images  \n\nYou can store or upload the processed images to any platform of your choice.  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nSimply connect nodes for the service where you want the images saved, for example:  \n\n- SQLite, MySQL, PostgreSQL, and other databases  \n- Google Drive, Dropbox, OneDrive, or Box  \n- S3 object storage, FTP servers, or WebDAV  \n- Airtable, Notion, Coda, or Smartsheet  \n- And many other services  \n\nBe sure to place these nodes **after the \"Download Image\" node**.  \nBy default, the output image files are named **`data`**. "
      },
      "typeVersion": 1
    },
    {
      "id": "1024a4b1-eecb-4fbd-8740-5ce45f238df0",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        180
      ],
      "parameters": {
        "color": 4,
        "width": 280,
        "height": 1160,
        "content": "### Input Image  \n\nThe **Replace Background** node can be substituted with any service that provides an input image URL along with a description of the desired background.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nYou can either use the **Form node** to manually enter image URLs for background removal, or connect nodes to any data source that provides image links, for example:\n\n- SQLite, MySQL, PostgreSQL, and other databases  \n- Google Drive, Dropbox, OneDrive, Box, and similar storage services  \n- S3 object storage, FTP servers, or WebDAV  \n- Airtable, Notion, Coda, or Smartsheet  \n- Google Sheets, Excel Online, or CSV files  \n- CRM systems like HubSpot, Pipedrive, or Salesforce  \n- CMS platforms like WordPress, Strapi, or Contentful  \n- Or virtually any other service that supplies image URLs"
      },
      "typeVersion": 1
    },
    {
      "id": "daaec5d9-342d-4f2f-85d2-0ca1a072dd4c",
      "name": "Download Image",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        700,
        380
      ],
      "parameters": {
        "url": "={{ $json.data.url }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "3f76cef0-807e-42e7-9a6f-4d078e86aada",
      "name": "APImage API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        400,
        380
      ],
      "parameters": {
        "url": "https://apimage.org/api/ai-replace-background",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "image_url",
              "value": "={{ $json[\"Image URL\"] }}"
            },
            {
              "name": "background_prompt",
              "value": "={{ $json[\"Background Description\"] }}"
            },
            {
              "name": "preserve_subject",
              "value": "0.8"
            },
            {
              "name": "light_direction",
              "value": "above"
            },
            {
              "name": "light_strength",
              "value": "0.6"
            },
            {
              "name": "output_format",
              "value": "png"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "ad8c0911-3d2b-4acb-ad4c-8b96e556e0d0",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        180
      ],
      "parameters": {
        "color": 4,
        "width": 280,
        "height": 460,
        "content": "### Replace + Relight Background\n\nThis is where the image processing happens. **APImage** removes the original background, applies the new one, and optimizes the overall lighting for a natural look.  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nOpen the **APImage API** node above and replace \"_YOUR_API_KEY_\" with your API Key. [Get your API Key here \ud83e\udc65](https://apimage.org/dashboard) \n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "ad068051-dcbe-49f9-8345-f42f1edc754c",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        600,
        180
      ],
      "parameters": {
        "color": 4,
        "width": 300,
        "height": 460,
        "content": "### Download Image  \n\nThis step downloads the processed image and makes it available for storage, sharing, or further processing.  \n"
      },
      "typeVersion": 1
    },
    {
      "id": "07ef7110-3d9e-4773-96f2-6f6c2143a012",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        660
      ],
      "parameters": {
        "width": 600,
        "height": 680,
        "content": "### Fequently Asked Questions \n\n**Q: How is background replacement different from background removal?**  \nA: Background removal makes the background transparent, while background replacement swaps it with a new one and adjusts lighting for a natural look.\n\n**Q: What types of images are supported?**  \nA: APImage works with standard image formats such as JPG, PNG, and WebP.  \n\n**Q: Can I choose a custom background?**  \nA: Yes. You can provide a description of the desired background, or integrate APImage into workflows that supply predefined background images.  \n\n**Q: What is the default filename for processed images?**  \nA: The default filename is **`data`**, unless you rename the file in your workflow.  \n\n**Q: Do I need to store the images locally?**  \nA: No. You can connect APImage to any supported service (databases, cloud storage, CMS platforms, APIs, etc.) and store images directly.  \n\n**Q: Can APImage be used in automated workflows?**  \nA: Absolutely. It integrates with n8n and can process images automatically from sources like databases, cloud storage, or APIs.  \n\n**Q: Does it also enhance image quality?**  \nA: APImage adjusts lighting and contrast to make background replacements look natural, but it does not perform full image upscaling.  \n\n**Q: Is there a limit to the number of images I can process?**  \nA: Processing limits depend on your subscription plan and allocated credits.  \n\n\n\n[APImage API Reference \ud83e\udc65](https://apimage.org/docs/api) | [APImage Customer Support \ud83e\udc65](https://apimage.org/support) | [Get your API Key \ud83e\udc65](https://apimage.org/dashboard)"
      },
      "typeVersion": 1
    },
    {
      "id": "3d8afd28-2752-4145-bfdf-29c64e59af3b",
      "name": "Replace Background (node can be exchanged)",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        80,
        380
      ],
      "parameters": {
        "options": {},
        "formTitle": "APImage Replace Background",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Image URL",
              "placeholder": "https://example.com/product-image.png",
              "requiredField": true
            },
            {
              "fieldLabel": "Background Description",
              "placeholder": "a modern office with natural lighting",
              "requiredField": true
            }
          ]
        },
        "formDescription": "Replaces the background of images"
      },
      "typeVersion": 2.2
    },
    {
      "id": "2f066144-49d7-4f26-8278-fc778e4f37d4",
      "name": "Store the output image (node can be exchanged)",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1020,
        380
      ],
      "parameters": {
        "name": "data",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root",
          "cachedResultName": "/ (Root folder)"
        }
      },
      "typeVersion": 3
    }
  ],
  "connections": {
    "APImage API": {
      "main": [
        [
          {
            "node": "Download Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Image": {
      "main": [
        [
          {
            "node": "Store the output image (node can be exchanged)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Replace Background (node can be exchanged)": {
      "main": [
        [
          {
            "node": "APImage API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow takes an image URL and a description of the desired background, then uses the APImage AI API to produce a high-quality image, preserving the subject and applying a natural-looking new background.

Source: https://n8n.io/workflows/8619/ — original creator credit. Request a take-down →

More Web Scraping workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Web Scraping

The Sora 2 API allows seamless generation of CGI ads, turning text prompts into stunning videos. This workflow automates the entire process from video generation to upload, notification, and file shar

Form Trigger, HTTP Request, Email Send +1
Web Scraping

Formtrigger Workflow. Uses formTrigger, googleDrive, httpRequest, stopAndError. Event-driven trigger; 28 nodes.

Form Trigger, Google Drive, HTTP Request +1
Web Scraping

Create CGI ads effortlessly by integrating the Google Veo3 API for video generation and uploading to Google Drive with seamless email notifications. On form submission: Triggers the workflow when a fo

Form Trigger, HTTP Request, Email Send +1
Web Scraping

This workflow automates the process of generating videos using the Veo 3 Fast API, uploading the video to Google Drive, and notifying the user via email. All tasks are executed seamlessly, ensuring a

Form Trigger, HTTP Request, Email Send +1
Web Scraping

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Form Trigger, HTTP Request, Google Drive +1