{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "001a2632-587f-4cb8-a7a0-0fbd0f1b4f48",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        -1040,
        3648
      ],
      "parameters": {
        "amount": 2
      },
      "typeVersion": 1.1
    },
    {
      "id": "b0a4dae6-2763-4067-bba2-e9ab0bc6b6b8",
      "name": "Merge2",
      "type": "n8n-nodes-base.merge",
      "position": [
        -960,
        3968
      ],
      "parameters": {},
      "typeVersion": 3.1
    },
    {
      "id": "73e8a5fd-2d1e-4d53-9b2d-2b818f9c80e9",
      "name": "resize logo",
      "type": "n8n-nodes-base.editImage",
      "position": [
        -1168,
        4128
      ],
      "parameters": {
        "width": 68.4,
        "height": 52.6,
        "options": {},
        "operation": "resize"
      },
      "typeVersion": 1
    },
    {
      "id": "282ea827-fe38-4f91-886a-993375a1417d",
      "name": "Merge Binary Items",
      "type": "n8n-nodes-base.code",
      "position": [
        -720,
        3968
      ],
      "parameters": {
        "jsCode": "const images = $input.all().reduce((acc, item, index) => {\n  acc[`data${index}`] = item.binary.data;\n  return acc;\n}, {});\nreturn [{ json: {}, binary: images }]"
      },
      "typeVersion": 2
    },
    {
      "id": "4b7f2891-54ef-4484-890e-3ee504b87725",
      "name": "If3",
      "type": "n8n-nodes-base.if",
      "position": [
        -720,
        3648
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "949170ea-a72b-4d90-881c-c18ab99a5800",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "COMPLETED"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "956ea698-f008-4fd6-8998-6170ffdb2dfa",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -2000,
        3648
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "3a2dcccc-ab9e-434c-8abe-04b673b36b7e",
      "name": "Link image",
      "type": "n8n-nodes-base.set",
      "position": [
        -1808,
        3648
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "0b01ca98-98a0-4232-be3b-a0fbc6d9bb52",
              "name": "image_url",
              "type": "string",
              "value": "=https://surecctv.com/uploads/images/2021/07/600x600-1627381898-single_product1-nk1080hir100af.jpg"
            },
            {
              "id": "756cc282-45f1-4e94-a835-9c7ff74b6c21",
              "name": "subject",
              "type": "string",
              "value": "technology"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b89307e1-1e3f-4a4b-a307-dc2f5df6256e",
      "name": "Create prompt for generate image",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -1600,
        3648
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Based on the topic: {{ $json.subject }}\n\nCreate an image prompt so I can put it into the Image AI Model to create a sharp, detailed illustration. The image prompt must be under 70 words, sharp and detailed, but no text or logos can be added to the image (Important).\n\nThe size of the article image for the website will be: 800x500 pixels"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "9f50d697-e11c-4cdb-8834-520d87a3b6f2",
      "name": "generate image",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1296,
        3648
      ],
      "parameters": {
        "url": "https://queue.fal.run/fal-ai/flux/dev/image-to-image",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"prompt\": \"{{ JSON.stringify($json.message.content).slice(1, -1) }}\",\n  \"image_url\": {{JSON.stringify($('Link image').item.json.image_url)}},\n  \"image_size\": {\n    \"width\": 800,\n    \"height\": 500\n  },\n  \"num_inference_steps\": 45,\n  \"guidance_scale\": 4.5,\n  \"num_images\": 1,\n  \"enable_safety_checker\": true\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Key xxxxx"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "dee77768-1f9c-44ab-ad5d-025d34e93325",
      "name": "check image finish",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -880,
        3648
      ],
      "parameters": {
        "url": "=https://queue.fal.run/fal-ai/flux/requests/{{ $json.request_id }}/status",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Key xxxx"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "d7fa1e0b-af07-48fa-9120-76ad416a46a1",
      "name": "Get image link",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -528,
        3632
      ],
      "parameters": {
        "url": "=https://queue.fal.run/fal-ai/flux/requests/{{ $json.request_id }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Key xxxxxx"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "b3638dd1-cc34-4361-9129-a5b1fcea8a60",
      "name": "Download image",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1584,
        3952
      ],
      "parameters": {
        "url": "={{ $json.images[0].url }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "9492aab5-5c3d-41f7-80db-dd3826d509e4",
      "name": "resize image",
      "type": "n8n-nodes-base.editImage",
      "position": [
        -1360,
        3952
      ],
      "parameters": {
        "width": 800,
        "options": {},
        "operation": "resize"
      },
      "typeVersion": 1
    },
    {
      "id": "86ff8705-ed79-467d-9e28-30db0a6e94ff",
      "name": "Get company's logo",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1360,
        4128
      ],
      "parameters": {
        "url": "=https://drive.google.com/uc?export=download&id=xxxxx",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "10b80e05-dc55-4cfd-bd59-c3dc90b9ced7",
      "name": "Composite image and logo",
      "type": "n8n-nodes-base.editImage",
      "position": [
        -512,
        3968
      ],
      "parameters": {
        "options": {},
        "operation": "composite",
        "positionX": 728,
        "dataPropertyName": "data0",
        "dataPropertyNameComposite": "data1"
      },
      "typeVersion": 1
    },
    {
      "id": "6eb031eb-0500-4574-8a85-d01fa9288582",
      "name": "Save on drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -320,
        3968
      ],
      "parameters": {
        "name": "={{ $('Loop Over Items').first().json.ten }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "1PlUL4-0iNYSXi4YTeTN8BfsPcqIxrwh5",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1PlUL4-0iNYSXi4YTeTN8BfsPcqIxrwh5",
          "cachedResultName": "image"
        },
        "inputDataFieldName": "data0"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "e7f70628-ac04-4a6b-8f0f-e512a15acb02",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2640,
        3568
      ],
      "parameters": {
        "color": 5,
        "width": 528,
        "height": 288,
        "content": "## Workflow Overview\n- **Input:** topic (`subject`) and a reference `image_url`.\n- **Prompting:** GPT-4o creates a <70-word, \u201cno text/logo\u201d> prompt for the image model.\n- **Generation:** HTTP Request \u2192 FAL Flux (`/image-to-image`) queues a job and returns `request_id`.\n- **Polling:** `Wait` + `check image finish` loop until `status == COMPLETED`.\n- **Post-process:** Download the image \u2192 resize to **800\u00d7500** \u2192 download logo \u2192 resize logo \u2192 composite.\n- **Output:** Save the final image to **Google Drive** with a dynamic file name."
      },
      "typeVersion": 1
    },
    {
      "id": "612b71a4-68fd-4ff5-a6f2-7ed682cef523",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2176,
        4064
      ],
      "parameters": {
        "width": 528,
        "height": 336,
        "content": "## Setup Checklist\n- **OpenAI / GPT-4o:** Connect your OpenAI credentials in the \u201cCreate prompt for generate image\u201d node.\n- **FAL API Keys:** Put real keys in BOTH HTTP Request nodes:\n  - `generate image` (POST \u2026/image-to-image)\n  - `check image finish` & `Get image link` (GET \u2026/requests/{id}[ /status ])\n- **Logo Source:** Update the logo URL in **\u201cGet company's logo\u201d** (Google Drive direct download link or any public URL).\n- **Google Drive:** Connect OAuth2 and set the **Folder ID** in **\u201cSave on drive\u201d**.\n- **Filename:** The Drive node uses: `$('Loop Over Items').first().json.ten` \u2192 change to your desired name field.\n- **Reference Image:** Update `image_url` in **\u201cLink image\u201d** (or pass it from upstream data).\n"
      },
      "typeVersion": 1
    },
    {
      "id": "242f0e7e-6f45-45f8-abbe-f327201bf378",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -928,
        4144
      ],
      "parameters": {
        "color": 3,
        "width": 528,
        "height": 288,
        "content": "## Notes & Tips\n- **Branding:** `resize logo` and the **Composite** node place the logo at `positionX: 728`. Tweak size/position for your layout.\n- **Polling Interval:** `Wait` node amount is **2** (seconds). Increase if you hit rate limits; decrease for faster checks.\n- **Safety:** The GPT prompt enforces **no text/logos** in the generated image\u2014keep this to avoid artifacts.\n- **Dimensions:** Final canvas is **800\u00d7500** (web article hero size). Adjust in `resize image` if your site uses a different aspect ratio.\n- **Error Handling:** If status never becomes `COMPLETED`, add an `If` branch for timeouts or retries.\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "If3": {
      "main": [
        [
          {
            "node": "Get image link",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "check image finish",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge2": {
      "main": [
        [
          {
            "node": "Merge Binary Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Link image": {
      "main": [
        [
          {
            "node": "Create prompt for generate image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "resize logo": {
      "main": [
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "resize image": {
      "main": [
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save on drive": {
      "main": [
        []
      ]
    },
    "Download image": {
      "main": [
        [
          {
            "node": "resize image",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get company's logo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get image link": {
      "main": [
        [
          {
            "node": "Download image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "generate image": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get company's logo": {
      "main": [
        [
          {
            "node": "resize logo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Binary Items": {
      "main": [
        [
          {
            "node": "Composite image and logo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "check image finish": {
      "main": [
        [
          {
            "node": "If3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Composite image and logo": {
      "main": [
        [
          {
            "node": "Save on drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create prompt for generate image": {
      "main": [
        [
          {
            "node": "generate image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Link image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}