AI Image Composition and Stitching with Gemini - n8n Workflow

Use this advanced n8n workflow to seamlessly stitch together separate input images into a single, cohesive image using the Gemini AI model. Learn how to handle base64 conversion within n8n templates for powerful AI generation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Digital Artists and Designers: Who need to quickly prototype storyboards or compose new scenes from existing asset libraries.
Marketing Teams: Automating the creation of consistent visual assets using product images.
Automation Engineers: Seeking advanced examples of using the n8n node ecosystem for handling complex binary data conversions (base64).
AI Enthusiasts: Interested in utilizing powerful multimodal AI models like Gemini within an n8n workflow.

Overview

Leveraging the multimodal capabilities of the Gemini API, this automation solves the challenge of combining disparate visual assets into a unified, consistent image based on a descriptive prompt. Traditional image editing requires tedious manual work, but this n8n workflow accelerates the process significantly. It demonstrates a sophisticated use case of an n8n template, showcasing how to manage binary data required for AI image-to-image manipulation, ensuring that the final output image is generated quickly and retains the specific style of the source materials. The final output of the n8n workflow is automatically saved to Google Drive, ensuring efficient storage and sharing of the generated content.

How it Works

This automation is initiated by a manual n8n trigger, but it can easily be replaced by a webhook or schedule.


  1. Image Retrieval: The n8n workflow starts by fetching three separate images ('Character', 'Dalmation', 'Sofa') using three HTTP Request n8n node actions, retrieving them as binary data.

  2. Data Preparation (Base64 Conversion): A Merge n8n node combines the inputs. Crucially, the Extract from File n8n node converts the binary image data into base64 strings, which is the required format for inputting visual data into the Gemini API.

  3. Aggregation: An Aggregate n8n node combines these three base64 strings into a single item, ready for the AI call.

  4. AI Composition: The Gemini Image Compose HTTP Request n8n node sends the instruction (prompt) and the three base64 images to the Gemini-2.0-flash model. The prompt instructs the AI on how to 'stitch' or compose the final scene.

  5. Output Processing: The Gemini API returns the composite image as a base64 string. A Set n8n node extracts this string and its MIME type.

  6. Binary Conversion & Upload: A Convert to File n8n node converts the base64 string back into standard binary data. The final step of the n8n workflow uses the Google Drive n8n node to upload the newly generated composite image for storage.

Installation Guide


  1. Import the n8n Workflow: Copy the provided JSON data and import it directly into your n8n instance via the 'Workflows' menu, using the 'Import from JSON' option.

  2. Gemini API Key: You must set up a credential for the Google Gemini (PaLM) API. The required n8n node uses this credential for authentication. Ensure your API key has access to the image generation models (note that these models may have geo-restrictions).

  3. Google Drive Setup: Configure the Google Drive n8n node with your required credentials. This n8n node needs access to upload files to your specified Drive folder (currently configured for 'My Drive').

  4. Execution: Once credentials are set, you can test the n8n workflow by clicking 'Execute Workflow' on the Manual Trigger n8n node.

Node Details

When clicking ‘Execute workflow’ (Manual Trigger): This n8n trigger manually starts the automation for testing and immediate use.
Character, Dalmation, Sofa (HTTP Request): These three n8n node instances fetch the source images (as binary data) from external URLs, providing the visual inputs for the composition process.
Extract from File (Core Logic): Converts the incoming binary image data into base64 properties (as required by the Gemini API). This is a critical data conversion n8n node in the flow.
Aggregate1 (Aggregate): Combines the multiple input items (the three base64 images) into a single item structure, enabling a single, consolidated request to the AI service.
Gemini Image Compose (HTTP Request): The heart of the n8n workflow. It sends a structured JSON payload containing the composition prompt and the three base64 images to the gemini-2.0-flash-preview-image-generation model for stitching.
Get Image Contents (Set): Parses the JSON response from Gemini, extracting the newly created image's base64 data and mime type for subsequent steps.
Convert to File (Core Logic): Reverses the earlier conversion, taking the AI-generated base64 string and converting it back into usable binary file data, preparing it for cloud storage.
Upload to Drive (Google Drive): The final n8n node, responsible for saving the generated, composite image to the configured Google Drive account.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by
Jimleuk
Jimleuk

Freelance consultant based in the UK specialising in AI-powered automations. I work with select clients tackling their most challenging projects. For business enquiries, send me an email at [email protected] LinkedIn: https://www.linkedin.com/in/jimleuk/ X/Twitter: https://x.com/jimle_uk

Featured*