{
  "name": "VietlinhAI | Tạo ảnh AI bằng Nano Banana, ghép tối đa 4 ảnh",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Chọn kiểu tạo ảnh",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Bạn muốn tạo ảnh theo kiểu nào?",
              "fieldType": "dropdown",
              "fieldName": "image_mode",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Prompt to Image"
                  },
                  {
                    "option": "Image to Image"
                  },
                  {
                    "option": "Multiple Image to Image"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Chọn model tạo ảnh",
              "fieldType": "dropdown",
              "fieldName": "image_model",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Nano Banana Pro"
                  },
                  {
                    "option": "Nano Banana 2"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Chọn tỷ lệ ảnh",
              "fieldType": "dropdown",
              "fieldName": "aspect_ratio",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Vuông 1:1"
                  },
                  {
                    "option": "Ngang 16:9"
                  },
                  {
                    "option": "Dọc 9:16"
                  },
                  {
                    "option": "Social 4:5"
                  },
                  {
                    "option": "Poster 3:4"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Chọn độ phân giải",
              "fieldType": "dropdown",
              "fieldName": "image_resolution",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Standard 1K"
                  },
                  {
                    "option": "High 2K"
                  },
                  {
                    "option": "Ultra 4K"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Chọn Style ảnh",
              "fieldType": "dropdown",
              "fieldName": "image_style",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Photorealistic"
                  },
                  {
                    "option": "Portrait"
                  },
                  {
                    "option": "Studio Portrait"
                  },
                  {
                    "option": "Portrait Cinematic"
                  },
                  {
                    "option": "Stock Photo"
                  },
                  {
                    "option": "3D Render"
                  },
                  {
                    "option": "Anime General"
                  },
                  {
                    "option": "Illustration"
                  },
                  {
                    "option": "Creative"
                  },
                  {
                    "option": "Watercolor"
                  },
                  {
                    "option": "None"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Nhập Prompt cho ảnh muốn tạo",
              "fieldName": "user_prompt"
            },
            {
              "fieldLabel": "Ảnh đầu vào 1",
              "fieldType": "file",
              "fieldName": "input_image_1"
            },
            {
              "fieldLabel": "Ảnh đầu vào 2",
              "fieldType": "file",
              "fieldName": "input_image_2"
            },
            {
              "fieldLabel": "Ảnh đầu vào 3",
              "fieldType": "file",
              "fieldName": "input_image_3"
            },
            {
              "fieldLabel": "Ảnh đầu vào 4",
              "fieldType": "file",
              "fieldName": "input_image_4"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.5,
      "position": [
        -928,
        640
      ],
      "id": "81026945-c7d4-49c6-9bf5-6b7350f93e78",
      "name": "Form thông tin đầu vào",
      "webhookId": "5750adc7-285e-4bac-b652-a0fa340a02a7"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5075911e-2399-45ab-81aa-6c251595b47a",
              "name": "image_mode",
              "value": "={{ $json.image_mode }}",
              "type": "string"
            },
            {
              "id": "51f3346a-77ea-4196-9ca0-9dfff51d81d2",
              "name": "image_model",
              "value": "={{ $json.image_model }}",
              "type": "string"
            },
            {
              "id": "4639d882-e3a0-4a85-b39c-0491c5a3d282",
              "name": "aspect_ratio",
              "value": "={{ $json.aspect_ratio }}",
              "type": "string"
            },
            {
              "id": "b143b490-6464-4f52-8b26-ea13b4941d48",
              "name": "image_resolution",
              "value": "={{ $json.image_resolution }}",
              "type": "string"
            },
            {
              "id": "00120548-e0f9-4db0-b77c-865aa90d34a3",
              "name": "image_style",
              "value": "={{ $json.image_style }}",
              "type": "string"
            },
            {
              "id": "5b9db31a-ccff-45d3-8e09-bc2c734741ac",
              "name": "user_prompt",
              "value": "={{ $json.user_prompt }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -704,
        640
      ],
      "id": "7a36d63e-1453-4347-a157-c5efa89f22fb",
      "name": "Nhận diện dữ liệu tạo ảnh"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{$json.image_mode}}",
                    "rightValue": "Prompt to Image",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "3d9599d1-7fa8-46d3-8c95-1359cf344d6d"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Prompt to Image"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "01153e39-6405-4a32-a848-298c6d88a997",
                    "leftValue": "={{ $json.image_mode }}",
                    "rightValue": "Image to Image",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Image to Image"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "f10c28cb-dd72-44f2-b9e2-3b24cd1c80f1",
                    "leftValue": "={{ $json.image_mode }}",
                    "rightValue": "Multiple Image to Image",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Multiple Image to Image"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -288,
        624
      ],
      "id": "899b0c3d-391b-4683-9eff-3ac5bbe2e3b0",
      "name": "Rẽ nhánh kiểu tạo ảnh"
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\n\nreturn items.map(item => {\n  const data = item.json || {};\n\n  const modelMap = {\n    \"Nano Banana Pro\": {\n      model: \"nano-banana-pro\",\n      generate_url: \"https://fal.run/fal-ai/nano-banana-pro\",\n      edit_url: \"https://fal.run/fal-ai/nano-banana-pro/edit\"\n    },\n    \"Nano Banana 2\": {\n      model: \"nano-banana-2\",\n      generate_url: \"https://fal.run/fal-ai/nano-banana-2\",\n      edit_url: \"https://fal.run/fal-ai/nano-banana-2/edit\"\n    }\n  };\n\n  const aspectRatioMap = {\n    \"Vuông 1:1\": \"1:1\",\n    \"Ngang 16:9\": \"16:9\",\n    \"Dọc 9:16\": \"9:16\",\n    \"Poster 3:4\": \"3:4\",\n    \"Social 4:5\": \"4:5\"\n  };\n\n  const resolutionMap = {\n    \"Standard 1K\": \"1K\",\n    \"High 2K\": \"2K\",\n    \"Ultra 4K\": \"4K\"\n  };\n\n  const styleMap = {\n    \"Photorealistic\": \"Photorealistic\",\n    \"Portrait\": \"Portrait\",\n    \"Studio Portrait\": \"Studio Portrait\",\n    \"Portrait Cinematic\": \"Portrait Cinematic\",\n    \"Stock Photo\": \"Stock Photo\",\n    \"3D Render\": \"3D Render\",\n    \"Anime General\": \"Anime General\",\n    \"Illustration\": \"Illustration\",\n    \"Creative\": \"Creative\",\n    \"Watercolor\": \"Watercolor\",\n    \"None\": \"None\"\n  };\n\n  const selectedModel = modelMap[data.image_model] || modelMap[\"Nano Banana 2\"];\n\n  const finalModel = selectedModel.model;\n  const falUrlGenerate = selectedModel.generate_url;\n  const falUrlEdit = selectedModel.edit_url;\n\n  const finalAspectRatio = aspectRatioMap[data.aspect_ratio] || \"1:1\";\n  const finalResolution = resolutionMap[data.image_resolution] || \"1K\";\n  const finalStyle = styleMap[data.image_style] || \"None\";\n  const outputFormat = \"jpeg\";\n\n  const finalPrompt = data.user_prompt || \"\";\n\n  let styleInstruction = \"\";\n\n  if (finalStyle === \"Watercolor\") {\n    styleInstruction = `\nStyle requirement:\nCreate the image as a soft watercolor painting.\nUse visible watercolor paper texture, hand-painted brush strokes, pastel color washes, soft edges, and gentle color bleeding.\nDo not make it photorealistic.\nDo not make it look like a camera photo.\n`;\n  } else if (finalStyle !== \"None\") {\n    styleInstruction = `\nStyle requirement:\nCreate the image in ${finalStyle} style.\nMake this style clearly visible in the final result.\n`;\n  }\n\n  const falPrompt = `${finalPrompt}\n\n${styleInstruction}`.trim();\n\n  const falBodyGenerate = {\n    prompt: falPrompt,\n    num_images: 1,\n    aspect_ratio: finalAspectRatio,\n    resolution: finalResolution,\n    output_format: outputFormat,\n    safety_tolerance: \"4\"\n  };\n\n  return {\n    json: {\n      ...data,\n\n      final_model: finalModel,\n      final_prompt: finalPrompt,\n      fal_prompt: falPrompt,\n\n      final_aspect_ratio: finalAspectRatio,\n      final_resolution: finalResolution,\n      final_style: finalStyle,\n      output_format: outputFormat,\n\n      fal_url_generate: falUrlGenerate,\n      fal_url_edit: falUrlEdit,\n\n      fal_body_generate: falBodyGenerate\n    },\n    binary: item.binary\n  };\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -512,
        640
      ],
      "id": "c570c5ea-e082-4ec8-baec-f2d08c2a2763",
      "name": "Code in JavaScript tạo final prompt"
    },
    {
      "parameters": {
        "operation": "uploadFile",
        "additionalFieldsFile": {}
      },
      "type": "n8n-nodes-cloudinary.cloudinary",
      "typeVersion": 1,
      "position": [
        496,
        1184
      ],
      "id": "3929b2d6-e6c4-42f0-bfe3-f191c19484fd",
      "name": "Upload an asset from file data"
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first();\nconst binary = item.binary || {};\n\nconst imageFields = [\n  \"input_image_1\",\n  \"input_image_2\",\n  \"input_image_3\",\n  \"input_image_4\"\n];\n\nconst output = [];\n\nfor (const field of imageFields) {\n  if (binary[field]) {\n    output.push({\n      json: {\n        ...item.json,\n        image_field: field\n      },\n      binary: {\n        data: binary[field]\n      }\n    });\n  }\n}\n\nreturn output;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        288,
        1184
      ],
      "id": "17bbde9c-0cd1-4f9d-b078-e4d0e0628bb3",
      "name": "Code tách ảnh để upload Cloud"
    },
    {
      "parameters": {
        "jsCode": "const cloudinaryItems = $input.all();\n\nif (!cloudinaryItems.length) {\n  throw new Error(\"Không có dữ liệu từ Cloudinary.\");\n}\n\nconst meta = $(\"Code in JavaScript tạo final prompt\").first().json || {};\n\nfunction getUrl(json) {\n  return (\n    json.secure_url ||\n    json.url ||\n    json.data?.secure_url ||\n    json.data?.url ||\n    json.result?.secure_url ||\n    json.result?.url ||\n    null\n  );\n}\n\nfunction normalizeAspectRatio(raw) {\n  const map = {\n    \"Vuông 1:1\": \"1:1\",\n    \"Ngang 16:9\": \"16:9\",\n    \"Dọc 9:16\": \"9:16\",\n    \"Social 4:5\": \"4:5\",\n    \"Poster 3:4\": \"3:4\",\n    \"1:1\": \"1:1\",\n    \"16:9\": \"16:9\",\n    \"9:16\": \"9:16\",\n    \"4:5\": \"4:5\",\n    \"3:4\": \"3:4\",\n    \"5:4\": \"5:4\",\n    \"4:3\": \"4:3\"\n  };\n\n  return map[raw] || \"1:1\";\n}\n\nfunction normalizeResolution(raw) {\n  const map = {\n    \"Standard 1K\": \"1K\",\n    \"High 2K\": \"2K\",\n    \"Ultra 4K\": \"4K\",\n    \"0.5K\": \"0.5K\",\n    \"1K\": \"1K\",\n    \"2K\": \"2K\",\n    \"4K\": \"4K\"\n  };\n\n  return map[raw] || \"1K\";\n}\n\nfunction normalizeOutputFormat(raw) {\n  const value = String(raw || \"jpeg\").toLowerCase();\n\n  if (value === \"jpg\") return \"jpeg\";\n  if (value === \"jpeg\") return \"jpeg\";\n  if (value === \"png\") return \"png\";\n  if (value === \"webp\") return \"webp\";\n\n  return \"jpeg\";\n}\n\nconst imageUrls = cloudinaryItems\n  .map(item => getUrl(item.json || {}))\n  .filter(Boolean)\n  .slice(0, 4);\n\nif (!imageUrls.length) {\n  throw new Error(\n    \"Không lấy được URL từ Cloudinary. Keys: \" +\n    JSON.stringify(Object.keys(cloudinaryItems[0]?.json || {}))\n  );\n}\n\nconst prompt =\n  meta.final_prompt ||\n  meta.user_prompt ||\n  meta.prompt ||\n  \"\";\n\nif (!prompt) {\n  throw new Error(\"Không tìm thấy prompt.\");\n}\n\nconst aspectRatio = normalizeAspectRatio(\n  meta.final_aspect_ratio || meta.aspect_ratio\n);\n\nconst resolution = normalizeResolution(\n  meta.final_resolution || meta.image_resolution\n);\n\nconst style =\n  meta.final_style ||\n  meta.image_style ||\n  \"None\";\n\nconst outputFmt = normalizeOutputFormat(\n  meta.output_format || \"jpeg\"\n);\n\nconst styleInstruction =\n  style !== \"None\" ? `\\nStyle: ${style}` : \"\";\n\nconst fullPrompt = `${prompt}\n\nUse ALL reference images:\n- Image 1: main subject/person\n- Image 2: outfit/clothing\n- Image 3: shoes/footwear\n- Image 4: bag/accessory\n\nCombine into one coherent, natural final image. Not a collage.\n${styleInstruction}`;\n\n// Fal Nano Banana Edit body\n// Không dùng image_size / quality ở đây\nconst falBody = {\n  prompt: fullPrompt,\n  image_urls: imageUrls,\n  num_images: 1,\n  aspect_ratio: aspectRatio,\n  resolution: resolution,\n  output_format: outputFmt,\n  safety_tolerance: \"4\",\n  limit_generations: true\n};\n\nreturn [\n  {\n    json: {\n      prompt,\n      aspect_ratio: aspectRatio,\n      resolution,\n      style,\n      output_format: outputFmt,\n      image_urls: imageUrls,\n      fal_body: falBody,\n      reference_image_count: imageUrls.length\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        704,
        1184
      ],
      "id": "f6f73cdf-96ce-473f-94dd-8b80e39bebf9",
      "name": "Code gom Url"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Code in JavaScript tạo final prompt').first().json.fal_url_edit }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Key YOUR_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.fal_body }}",
        "options": {
          "timeout": 120000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        912,
        1184
      ],
      "id": "3c4e9c0b-1fe0-4710-9e5f-3770369e1030",
      "name": "Fal AI Image Generation"
    },
    {
      "parameters": {
        "url": "={{ $json.images[0].url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1120,
        1184
      ],
      "id": "8a6f0b44-60e2-4e90-bdb2-e4c09a5ea30e",
      "name": "Download ảnh kết quả"
    },
    {
      "parameters": {
        "inputDataFieldName": "=data",
        "name": "=generated_{{ $now.toFormat('yyyyMMdd_HHmmss') }}.jpg",
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list",
          "cachedResultName": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive"
        },
        "folderId": {
          "__rl": true,
          "value": "",
          "mode": "list",
          "cachedResultName": "-- Chọn thư mục lưu ảnh của bạn --",
          "cachedResultUrl": ""
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1344,
        1184
      ],
      "id": "c6bbdfc7-b814-438c-8b85-df41729a1e70",
      "name": "Lưu ảnh vào Google Drive"
    },
    {
      "parameters": {
        "content": "## PROMPT TO IMAGE FAL AI\n",
        "height": 416,
        "width": 1648,
        "color": "#191C33"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "204b3721-96ad-48a2-9c72-116aa6470f6f",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "url": "={{ $json.images[0].url }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        672,
        160
      ],
      "id": "db8e619e-fc48-4d22-9de5-3c6bbb8b28d3",
      "name": "Get Image"
    },
    {
      "parameters": {
        "amount": 10
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        896,
        640
      ],
      "id": "8c5eb4c0-e9f6-43e4-bded-aadf7c1dbc91",
      "name": "Wait1",
      "webhookId": "5f25ea17-49b4-484a-851e-aeba5dc99825"
    },
    {
      "parameters": {
        "content": "## IMAGE TO IMAGE FAL AI\n",
        "height": 432,
        "width": 1984,
        "color": "#191C33"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        480
      ],
      "id": "2786a976-8261-4d34-82cc-af96f27e5fe8",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "url": "={{ $json.images[0].url }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1104,
        640
      ],
      "id": "04e90903-308a-4ca1-8072-a8e491d5d5ec",
      "name": "Get Image 1"
    },
    {
      "parameters": {
        "inputDataFieldName": "=data",
        "name": "={{ 'generated_' + $now.toFormat('yyyyMMdd_HHmmss') + '_Prompt2Image.jpg' }}",
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list",
          "cachedResultName": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive"
        },
        "folderId": {
          "__rl": true,
          "value": "",
          "mode": "list",
          "cachedResultName": "-- Chọn thư mục lưu ảnh của bạn --",
          "cachedResultUrl": ""
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1104,
        160
      ],
      "id": "859ceecf-778d-468f-9d5c-ddabc4939fe4",
      "name": "Lưu ảnh vào Google Drive1"
    },
    {
      "parameters": {
        "url": "={{ $('Fal AI Image Generation2').item.json.images[0].url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        896,
        160
      ],
      "id": "531d9468-ecdf-41d5-810b-a6dfd42e4ddf",
      "name": "Download ảnh kết quả1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.imgbb.com/1/upload",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "YOUR_KEY"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "image",
              "inputDataFieldName": "input_image_1"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        272,
        640
      ],
      "id": "6aa40a32-fc5b-4480-89cb-6ea64be7dbe5",
      "name": "Get Url bằng ImgBB"
    },
    {
      "parameters": {
        "url": "={{ $('Fal AI Image Generation1').item.json.images[0].url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        1328,
        640
      ],
      "id": "2226b5b1-f3b5-4674-b882-b73021360825",
      "name": "Download ảnh kết quả2"
    },
    {
      "parameters": {
        "inputDataFieldName": "=data",
        "name": "={{ 'generated_' + $now.toFormat('yyyyMMdd_HHmmss') + '_Image2Image.jpg' }}",
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list",
          "cachedResultName": "My Drive",
          "cachedResultUrl": "https://drive.google.com/drive/my-drive"
        },
        "folderId": {
          "__rl": true,
          "value": "",
          "mode": "list",
          "cachedResultName": "-- Chọn thư mục lưu ảnh của bạn --",
          "cachedResultUrl": ""
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1536,
        640
      ],
      "id": "6b3b8967-651f-4735-a8cd-e481e2b27985",
      "name": "Lưu ảnh vào Google Drive2"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Code in JavaScript tạo final prompt').first().json.fal_url_edit }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Key YOUR_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.fal_body }}",
        "options": {
          "timeout": 120000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        688,
        640
      ],
      "id": "709cbca3-cd31-403e-920a-62415517a8e6",
      "name": "Fal AI Image Generation1"
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first();\nconst meta = $(\"Code in JavaScript tạo final prompt\").first().json;\n\n// Lấy URL ảnh trực tiếp từ kết quả ImgBB\nconst imageUrl =\n  item.json?.data?.url ||\n  item.json?.url ||\n  null;\n\nif (!imageUrl) {\n  throw new Error(\"Không lấy được URL ảnh từ ImgBB.\");\n}\n\n// Lấy prompt\nconst prompt =\n  meta.final_prompt ||\n  meta.user_prompt ||\n  \"\";\n\nif (!prompt) {\n  throw new Error(\"Không tìm thấy prompt.\");\n}\n\n// Quy đổi tỷ lệ ảnh\nconst aspectRatioMap = {\n  \"Vuông 1:1\": \"1:1\",\n  \"Ngang 16:9\": \"16:9\",\n  \"Dọc 9:16\": \"9:16\",\n  \"Social 4:5\": \"4:5\",\n  \"Poster 3:4\": \"3:4\"\n};\n\n// Quy đổi độ phân giải\nconst resolutionMap = {\n  \"Standard 1K\": \"1K\",\n  \"High 2K\": \"2K\",\n  \"Ultra 4K\": \"4K\"\n};\n\nconst aspectRatio =\n  aspectRatioMap[meta.final_aspect_ratio] ||\n  meta.final_aspect_ratio ||\n  \"1:1\";\n\nconst resolution =\n  resolutionMap[meta.final_resolution] ||\n  meta.final_resolution ||\n  \"1K\";\n\nconst style = meta.final_style || \"None\";\n\nconst styleInstruction =\n  style !== \"None\"\n    ? `\\nStyle: ${style}`\n    : \"\";\n\nconst fullPrompt = `${prompt}${styleInstruction}`;\n\n// Body gửi sang Fal.ai\nconst falBody = {\n  prompt: fullPrompt,\n\n  // Fal.ai edit yêu cầu image_urls là một mảng\n  image_urls: [imageUrl],\n\n  num_images: 1,\n  aspect_ratio: aspectRatio,\n  resolution: resolution,\n  output_format: \"jpeg\",\n  safety_tolerance: \"4\"\n};\n\nreturn [\n  {\n    json: {\n      prompt: fullPrompt,\n      aspect_ratio: aspectRatio,\n      resolution,\n      style,\n\n      // Trả ra dạng mảng để dễ kiểm tra trong n8n\n      image_urls: [imageUrl],\n\n      fal_body: falBody\n    }\n  }\n];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        640
      ],
      "id": "4d95dfb6-c284-439e-b3f5-8ff300e0cc2c",
      "name": "Code gom Url1"
    },
    {
      "parameters": {
        "content": "## MULTIPLE IMAGE TO IMAGE  FAL AI\n",
        "height": 416,
        "width": 1968,
        "color": "#191C33"
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        1024
      ],
      "id": "ffdef3ec-cb76-4d27-8bb0-cfcbf5efd533",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## THÔNG TIN PROMPT VÀ ẢNH \n",
        "height": 592,
        "width": 976,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1040,
        400
      ],
      "id": "ca402a7a-bcce-47b1-a003-c63d99f259f2",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $json.fal_url_generate }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Key YOUR_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json.fal_body_generate }}",
        "options": {
          "timeout": 120000
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        240,
        160
      ],
      "id": "a9e89150-5f89-4728-86e9-90f5be69beea",
      "name": "Fal AI Image Generation2"
    },
    {
      "parameters": {
        "amount": 10
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        464,
        160
      ],
      "id": "45aa0c37-f6a8-4b82-b6b9-c1884bb929e2",
      "name": "Wait",
      "webhookId": "9b21171d-2a25-4839-bda6-54217f7714f3"
    }
  ],
  "pinData": {},
  "connections": {
    "Form thông tin đầu vào": {
      "main": [
        [
          {
            "node": "Nhận diện dữ liệu tạo ảnh",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Nhận diện dữ liệu tạo ảnh": {
      "main": [
        [
          {
            "node": "Code in JavaScript tạo final prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript tạo final prompt": {
      "main": [
        [
          {
            "node": "Rẽ nhánh kiểu tạo ảnh",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code tách ảnh để upload Cloud": {
      "main": [
        [
          {
            "node": "Upload an asset from file data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload an asset from file data": {
      "main": [
        [
          {
            "node": "Code gom Url",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code gom Url": {
      "main": [
        [
          {
            "node": "Fal AI Image Generation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fal AI Image Generation": {
      "main": [
        [
          {
            "node": "Download ảnh kết quả",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download ảnh kết quả": {
      "main": [
        [
          {
            "node": "Lưu ảnh vào Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Image": {
      "main": [
        [
          {
            "node": "Download ảnh kết quả1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "Get Image 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Image 1": {
      "main": [
        [
          {
            "node": "Download ảnh kết quả2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download ảnh kết quả1": {
      "main": [
        [
          {
            "node": "Lưu ảnh vào Google Drive1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Url bằng ImgBB": {
      "main": [
        [
          {
            "node": "Code gom Url1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download ảnh kết quả2": {
      "main": [
        [
          {
            "node": "Lưu ảnh vào Google Drive2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fal AI Image Generation1": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code gom Url1": {
      "main": [
        [
          {
            "node": "Fal AI Image Generation1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fal AI Image Generation2": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Get Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Rẽ nhánh kiểu tạo ảnh": {
      "main": [
        [
          {
            "node": "Fal AI Image Generation2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Url bằng ImgBB",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code tách ảnh để upload Cloud",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "nodeGroups": [],
  "tags": []
}