{
  "id": "8iRcKiCUN5HuBdKZ",
  "name": "N8N-ImageGen",
  "tags": [],
  "nodes": [
    {
      "id": "c75b96e0-cbbf-434d-83bb-a02694c2b5ba",
      "name": "Trigger \u2014 Receive Query",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        464,
        240
      ],
      "parameters": {
        "inputSource": "passthrough"
      },
      "typeVersion": 1.1
    },
    {
      "id": "cd0ae13e-ef87-47fe-b974-bd1636978473",
      "name": "Gemini \u2014 Generate Image",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        688,
        240
      ],
      "parameters": {
        "prompt": "=create a professional photorealistic image for the following: {{ $json.query }}\n\n",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-3-pro-image-preview",
          "cachedResultName": "models/gemini-3-pro-image-preview"
        },
        "options": {
          "binaryPropertyOutput": "data"
        },
        "resource": "image"
      },
      "typeVersion": 1
    },
    {
      "id": "9eff4394-d7a4-4830-b281-1e29f575f91e",
      "name": "WP \u2014 Upload Image to Media Library",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        944,
        240
      ],
      "parameters": {
        "url": "https://your-wordpress-site.com/wp-json/wp/v2/media",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "binaryData",
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Disposition",
              "value": "=attachment; filename=\"article-image-{{ $now.toMillis() }}.jpg\""
            }
          ]
        },
        "inputDataFieldName": "data",
        "nodeCredentialType": "wordpressApi"
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "waitBetweenTries": 5000
    },
    {
      "id": "c92d76ee-c4df-4aa2-846e-41828f2cb495",
      "name": "Set \u2014 Return Image Data",
      "type": "n8n-nodes-base.set",
      "position": [
        1248,
        240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "url-out",
              "name": "url",
              "type": "string",
              "value": "={{ $json.source_url }}"
            },
            {
              "id": "media-id-out",
              "name": "media_id",
              "type": "number",
              "value": "={{ $json.id }}"
            },
            {
              "id": "alt-out",
              "name": "alt",
              "type": "string",
              "value": "={{ $json.alt_text || '' }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "7abd1f7f-f41f-4982-a7cd-ac3d580bd436",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        32
      ],
      "parameters": {
        "width": 400,
        "height": 808,
        "content": "## \ud83d\uddbc\ufe0f Generate AI Image with Gemini and Upload to WordPress\n**Sub-workflow** \u2014 Called by a parent workflow to generate a photorealistic AI image from a text prompt and upload it directly to the WordPress Media Library.\n\n### How it works\n1. Receives a `query` string field via the Execute Workflow Trigger (passthrough mode).\n2. Sends the query to **Google Gemini** to generate a professional, photorealistic image.\n3. Uploads the resulting binary image to your **WordPress Media Library** via the WP REST API.\n4. Returns `url`, `media_id`, and `alt` to the calling parent workflow.\n\n### Setup\n1. Connect your **Google Gemini (PaLM) API** credential to the **Gemini \u2014 Generate Image** node.\n2. Connect your **WordPress API** credential to the **WP \u2014 Upload Image to Media Library** node.\n3. Update the WordPress URL in that node to point to your site: `https://your-site.com/wp-json/wp/v2/media`.\n4. Call this workflow from a parent workflow, passing a JSON field named `query`.\n\n### Customization\n- Change the Gemini model in **Gemini \u2014 Generate Image** to adjust image quality or style.\n- Edit the prompt prefix in the same node to change the default photorealistic tone.\n- The filename in the `Content-Disposition` header uses a timestamp \u2014 adjust as needed.\n\n\u26a0\ufe0f **Community Node Notice:** This workflow uses `@n8n/n8n-nodes-langchain.googleGemini`, a LangChain community node. It requires a **self-hosted n8n instance** with the LangChain add-on installed."
      },
      "typeVersion": 1
    },
    {
      "id": "8f186354-e7b7-49ea-a825-5b98fbc9544b",
      "name": "Trigger Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        416,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 200,
        "height": 400,
        "content": "## 1 \u2014 Trigger\nReceives `query` from a parent workflow via Execute Workflow Trigger (passthrough). No transformation \u2014 raw input passes through."
      },
      "typeVersion": 1
    },
    {
      "id": "b7c0cd64-26f2-4451-a285-1c0b6ef5236f",
      "name": "Gemini Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        624,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 220,
        "height": 400,
        "content": "## 2 \u2014 Image Generation\nCalls Google Gemini image model with a photorealistic prompt built from the incoming `query`. Binary output stored in the `data` field."
      },
      "typeVersion": 1
    },
    {
      "id": "c316bcef-6b45-4e11-89a0-20b64d328211",
      "name": "WP Upload Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 408,
        "content": "## 3 \u2014 WordPress Upload\nPOSTs binary image data to the WordPress Media Library REST endpoint. Retries once on failure (5s delay). Continues on error to prevent blocking the parent workflow.\n\n**Update the URL** to your own WordPress site before activating."
      },
      "typeVersion": 1
    },
    {
      "id": "285c5848-b816-4dd8-8eca-08652b451d2d",
      "name": "Return Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1152,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 248,
        "height": 400,
        "content": "## 4 \u2014 Return Data\nMaps WordPress response to clean output fields: `url`, `media_id`, `alt`. These values are returned to the calling parent workflow."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "8f49dca0-b9b7-4447-af25-a452d1a588bb",
  "connections": {
    "Gemini \u2014 Generate Image": {
      "main": [
        [
          {
            "node": "WP \u2014 Upload Image to Media Library",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger \u2014 Receive Query": {
      "main": [
        [
          {
            "node": "Gemini \u2014 Generate Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WP \u2014 Upload Image to Media Library": {
      "main": [
        [
          {
            "node": "Set \u2014 Return Image Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}