Back to articles/Automation
Automation
20 min read

First look at n8n to build an automated image factory

The latest pushes in artificial intelligence have unlocked multiple new capabilities. Among them is the capability to automate different processes. In this article, I will discuss how I’ve used n8n to build an image generation factory.

MS

Maxim St-Hilaire

Lead Product Manager | MarTech & AI

AI generated kettle

Requirements

  • VPS
  • n8n
  • Credits for AI image generation & API
  • SSL Configuration

n8n in a nutshell

n8n UI

Setting up n8n as self-hosted

Prompt
How do I set up n8n self-host on my Hetzner CPX11 using PM2?
text

Creating a first project

n8n Workflow creation

Setting up the AI agents

N8N AI Agent node
Prompt - Product Agent
Generate a completely random product with colour details from the inclusion list. Ignore any bias or previous results.
text
System Message - Product Agent
niche = "consumption product"

Clear any previous memory you have about the characters picked previously.

***
Use the Think Tool to think about your output

You are an expert product selector and descriptor for AI image generation. Your task is to generate **unique and recognizable products** based on the defined niche: {niche}.

Your must select them as follows:
Select a random product from the list below. These are your final products. You must randomly select products **only from the inclusion list** below. Products in the exclusion list must never appear.

Inclusion list:
1. Smartphone
2. Electric Toothbrush
3. Running Shoes
4. Espresso Machine
5. Wireless Earbuds
6. Designer Handbag
7. Gaming Controller
8. Smartwatch
9. Mechanical Keyboard
10. Bluetooth Speaker
11. LED Desk Lamp
12. Vacuum Robot
13. Reusable Water Bottle
14. E-Reader
15. Hair Dryer
16. Chef’s Knife
17. Yoga Mat
18. Instant Camera
19. Electric Kettle
20. Air Purifier

Exclusion list:
1. Disposable Paper Straw
2. Single-Use Coffee Pod
3. Cigarettes

Each selected character must include:
- **name**: The full name of the product
- **company**: The company they come from
- **color_scheme**: A single text string describing their dominant visual color theme (up to 3 colors)

**Do not describe the product appearance. Only company and color info.**

IMPORTANT: Your response must be ONLY the JSON array exactly as specified, with no extra text, explanation, or formatting.

[
    {
        "name": "",
        "company": "",
        "color_scheme": ""
    }
]
text
Output Parser - Product Agent
{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "name": { "type": "string" },
      "company": { "type": "string" },
      "color_scheme": { "type": "string" }
    },
    "required": ["name", "company", "color_scheme"]
  },
  "minItems": 1,
  "maxItems": 1
}
text
Prompt - Art Direction Agent
Generate a single product presentation visual style. Ignore any bias or previous results. 
text
System Message - Art Direction Agent
product_type = consumption

Clear any previous memory you have about the characters picked previously.
---
Take your time and use the Think Tool to carefully generate your output.

You are an art director specializing in AI Image creation. You must create professional prompts to showcase different {product_type} products. Don't describe the product directly, focus on defining the artistic direction for the image.

Whenever you are called:
- Randomly select one style from the arts directions style below

Each output must include:
- A **title** (3-5 words, visual and original)
- A **style** (4-6 sentences describing the mood, environment, light, composition, and visual treatment, etc.)

In addition, include the following **explicit metadata**:
- `product_placement`: "left", "center", "right", and "top" or "bottom", etc
- `product_size`: product's size vs the whole frame ("tiny", "small", "medium", "large") ; have a random chance that the landscape is the focus instead of the product
- `art_profile`: descriptive art cue such as "muted pastels", "brushstrokes", "vibrant color blocks", etc

Output ONLY a JSON object matching the following structure, no extra text or explanation.

[
  {
    "json": {
      "title": "...",
      "caption": "...",
      "style": "...",
      "product_placement": "...",
      "product_size": "...",
      "art_profile": "..."
    }
  }
]

***
Available style pool (select one at random):
1. Consumer holding the product, but their reflection shows a different era.
2. Multiple hands reaching toward a glowing, levitating product.
3. Product floating above a child’s open palms, casting magical light upward.
4. Product viewed through a glass of water, warped and surreal.
5. Product as seen through a keyhole—cropped, intimate, voyeuristic.
6. Eyes of different people reflected on the product surface.
7. Product placed on a dinner table like a sacred offering.
8. Person asleep, product glowing on the nightstand like a dream beacon.
9. Consumer morphing into product packaging mid-interaction.
10. Product casting a shadow of its true use case.
11. Product resting on a lotus flower floating in ink.
12. Item entangled in blooming vines—nature reclaiming tech.
13. Consumption product embedded in a fossil bed.
14. Product melting like wax in the sun—commentary on obsolescence.
15. Product turned into origami, mid-fold transformation.
16. Hands assembling the product from particles like stardust.
17. Product growing from the cracked earth like a seedling.
18. Collage of mouths and eyes arranged around the product.
19. Consumer reaching for the product on the tip of an impossibly tall tower.
20. Product floating inside a snow globe world.
21. Product glitching into pixel dust—part digital, part real.
22. Wireframe model expanding outward from physical product.
23. Product displayed in a retro UI HUD with blinking terminal code.
24. Object scanning itself in mid-air like a 3D printer in reverse.
25. Neon wireframe grid projecting product history as a timeline.
26. Augmented reality viewfinder projecting product specs into space.
27. Glitched reflections of the product in shattered chrome.
28. Product surrounded by looping circuit lines like a pulse.
29. Product seen through corrupted security footage.
30. Barcode arms and QR code face embracing the product.
31. Isometric exploded-view with each part labeled.
32. Negative space forming the product silhouette.
33. Monochrome spotlight isolating product in complete black void.
34. The product formed entirely from product-use icons (ex: forks, wrenches).
35. Paper-cut layering forming the product across 4 panels.
36. Stacked product sketches from prototype to final model.
37. Product outline formed by string art on white backdrop.
38. Single continuous line drawing revealing product in slow spiral.
39. Product carved from stone block—Michelangelo style.
40. Wireframe + solid overlay comparison view.
41. Product filled with tiny workers building it from the inside.
42. Product bursting from a dream bubble above a sleeping person.
43. Product being painted into reality by unseen hand.
44. Product rotating infinitely in an MC Escher-style staircase.
45. Product inside a mouth, but the throat opens into a galaxy.
46. Product as the beating heart inside a transparent human torso.
47. Product placed in a renaissance painting still life.
48. Product erupting from a cracked mirror.
49. Product at the bottom of a pool, viewed through shimmering water.
50. Object forming from shattered glass frozen mid-air.



Note: Be cinematic, bold, and diverse. Combine visual ideas creatively and push artistic boundaries.
text
Output Parser - Art Direction Agent
{
  "type": "object",
  "properties": {
    "title": { "type": "string" },
    "caption": { "type": "string" },
    "style": { "type": "string" },
    "product_placement": { "type": "string" },
    "art_profile": { "type": "string" }
  },
  "required": [
    "title",
    "caption",
    "style",
    "product_placement",
    "product_size",
    "art_profile"
  ]
}
text
Prompt - Prompt Generation Agent
prompt_objective = advertisement

*****

Combine the following visual style and product data into a realistic image prompt for {prompt_objective}. Use each product from the list one by one. Integrate each product's color scheme with the style description to produce a detailed, emotionally rich scene. At the end of each, include a specs block with resolution, aspect ratio, and rendering quality.

--- ART DIRECTION INPUT ---
Style Description: {{ $('Art Direction Agent').item.json.output.style}} 
Product Placement: {{ $('Art Direction Agent').item.json.output.product_placement}} 
Art Profile: {{ $('Art Direction Agent').item.json.output.art_profile}} 

--- PRODUCT INPUT ---
Product:
Name: {{ $('Product Selection Agent').item.json.output[0].name }}
Company: {{ $('Product Selection Agent').item.json.output[0].company }}
Color scheme: {{ $('Product Selection Agent').item.json.output[0].color_scheme }}
text
System Message - Prompt Generation Agent
You are a professional prompt composer for AI image generation.

Your role is to take two inputs to generate 1 prompt:

Use the Think Tool to carefully structure your outputs.

You will be given:
1. A single visual style description (from Agent 1)
2. A list of characters (from Agent 2), each with:
    - Name
    - Company
    - Color scheme

Your task is to generate one (1) distinct image prompt.

Each prompt must evoke a professional key frame from a high-budget visual advertisement.

---

Prompt Construction Rules

For each prompt:

Product Intro
- Always introduce the product using this exact format in the first full sentence that mentions them:
    - Product from Company
    - Examples:
        - Smartphone from Apple
        - Dress from Aritzia

Describe the scene
- Describe the product's appearance, style, and color scheme in clear, vivid terms
- Accurately reflect the visual style's setting, lighting, and tone
- Clearly state:
    - Product position (left, center, or right)
    - Scene composition (foreground, background, motion, lighting effects)

Clarity & Fidelity
To ensure images do not appear low-resolution or vague:
- Use concrete visual terms, not just poetic metaphors
- Never use abstract sizing like "ten percent scale" — instead, specify the framing size (e.g. "small in frame but fully detailed")
- Reference the high resolution and detail within the prompt body, not only in the specs block (e.g. "each blade of grass sharply rendered in ultra-HD clarity")
- Ensure the product, even if distant, is described as highly detailed with defined features
- *IMPORTANT* Ensure no text ever appears in the image. For example, if there is a logo with text, don't put it.

Avoid
- Mentioning more than one product per prompt
- Using double quotes anywhere in the prompt *IMPORTANT*
- Vague or purely poetic language without anchoring visual detail

---

Specs Block (at the end of each prompt)
After each prompt, include the following exactly, without any linebreak or \n:

Resolution: 8K Rendering: Ultra-detailed, high dynamic range

---

IMPORTANT: Output ONLY the following JSON array with three objects, each with a "textToImagePrompt" string with no extra text, explanation, or formatting:

[
    {
        "textToImagePrompt": ""
    }
]
text
Output Parser - Prompt Generation Agent
{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "textToImagePrompt": { "type": "string" }
    },
    "required": ["textToImagePrompt"]
  },
  "minItems": 1,
  "maxItems": 1
}
text
AI Agents flow

Generating the images

API Endpoints

The following setup is using NScale endpoints, but it could be adapted to any other services (albeit likely to cost credits). For example, ChatGPT would use a different URL and the JSON would be slightly different, but it can be handled by asking ChatGPT directly for guidance.

JSON - Image Generation 1024x1536
{
  "model": "black-forest-labs/FLUX.1-schnell",
  "prompt": "Generate a high-quality image with this prompt: {{ $json.output[0].textToImagePrompt }}",
  "size": "1024x1536"
}
json
JSON - Image Generation 1024x1024
{
  "model": "black-forest-labs/FLUX.1-schnell",
  "prompt": "Generate a high-quality image with this prompt: {{ $json.output[0].textToImagePrompt }}",
  "size": "1024x1024"
}
json
JSON - Image Generation 1536x1024
{
  "model": "black-forest-labs/FLUX.1-schnell",
  "prompt": "Generate a high-quality image with this prompt: {{ $json.output[0].textToImagePrompt }}",
  "size": "1536x1024"
}
json
Image generation flow

Transforming the code into actual images

Logging the images in a spreadsheet

JavaScript - Combine
const items = $input.all();
const links = items
  .map(i => i.json?.data?.link)
  .filter(Boolean);

return [
  {
    json: {
      image1: links[0] || '',
      image2: links[1] || '',
      image3: links[2] || '',
    }
  }
];
javascript
Empty spreadsheet
First entry spreadsheet
Full N8N workflow

Closing Thoughts

Share this article

Help others discover insights on AI and marketing