# Gemini Imagen
<!--
ref: @integrations/gemini-imagen
tags: [image generation, image editing, AI models, Gemini, creative tools]
aliases: [imagen, nano-banana, gemini-image, image-generation]
triggers: [need to create images from text, want to edit an existing image, require high-quality visuals, looking for fast image generation]
trigger_prompt: When a user needs to generate images based on text prompts or modify existing images while preserving their original elements.
category: integration
last_reviewed: 2026-04-30
complements: [@integrations/notion, @integrations/apify]
audience: [claude-code-user, agent-author]
version: 6
updated_at: 2026-07-14T20:44:21.754Z
-->

Generate and edit images using Gemini Imagen's advanced models for text-to-image and image editing.

## Models

| Model | ID | Use Case |
|-------|----|----------|
| Imagen 4 | `imagen-4.0-generate-001` | Text-to-image generation. Best for initial creation. |
| Imagen 4 Ultra | `imagen-4.0-ultra-generate-001` | Higher quality text-to-image. |
| Imagen 4 Fast | `imagen-4.0-fast-generate-001` | Fast text-to-image. Lower quality. |
| Nano Banana | `gemini-2.5-flash-image` | **Image editing.** Send source image + edit prompt. |
| Nano Banana Pro | `gemini-3-pro-image-preview` | Professional image editing. |
| Nano Banana 2 | `gemini-3.1-flash-image-preview` | Fast image editing. |

**Rule of thumb:** Use Imagen 4 to create from scratch, Nano Banana to iterate on an existing image.

## Choosing Your Approach

| Situation | Model | Why |
|-----------|-------|-----|
| First generation from text description | Imagen 4 | Best quality text-to-image |
| Iterating on a generated image | Nano Banana | Preserves source, makes targeted edits |
| Color/style change on existing image | Nano Banana | Edit, don't regenerate |
| Simplify/reduce detail | Nano Banana | Edit, don't regenerate |
| Background removal/swap | Nano Banana | Edit, don't regenerate |
| Completely different concept | Imagen 4 | Start fresh |

**Critical:** When the user approves an image and wants modifications, ALWAYS use image editing (Nano Banana) with the approved image as input. Never re-describe via text prompt — you will lose what they liked.

## Text-to-Image — Imagen 4

### curl

```bash
curl -s "https://generativelanguage.googleapis.com/v1beta/models/imagen-4.0-generate-001:predict?key=$GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "instances": [{"prompt": "YOUR PROMPT HERE"}],
    "parameters": {
      "sampleCount": 1,
      "aspectRatio": "1:1",
      "safetySetting": "block_low_and_above"
    }
  }'
```

**Decode response:**
```bash
echo "$response" | jq -r '.predictions[0].bytesBase64Encoded' | base64 -d > output.png
```

**Multiple images:** Set `"sampleCount": 4` — returns `predictions[0..3]`.

### Node.js SDK

```typescript
import { GoogleGenAI } from '@google/genai';

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

const result = await ai.models.generateImages({
  model: 'imagen-4.0-generate-001',
  prompt: promptText,
  config: {
    numberOfImages: 1,
    aspectRatio: '1:1',
    safetySetting: 'block_low_and_above',
  },
});

const buffer = Buffer.from(result.generatedImages[0].image.imageBytes, 'base64');
```

### Python

```python
import requests, base64, os

resp = requests.post(
    f"https://generativelanguage.googleapis.com/v1beta/models/imagen-4.0-generate-001:predict?key={os.environ['GEMINI_API_KEY']}",
    json={
        "instances": [{"prompt": prompt}],
        "parameters": {"sampleCount": 1, "aspectRatio": "1:1", "safetySetting": "block_low_and_above"}
    }
)
img = base64.b64decode(resp.json()['predictions'][0]['bytesBase64Encoded'])
with open('output.png', 'wb') as f:
    f.write(img)
```

## Image Editing — Nano Banana

Send a source image + text edit instruction. The model modifies the image while preserving what you don't mention.

### curl

```bash
# Encode source image
SOURCE_B64=$(base64 -i source.png)

curl -s "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=$GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"contents\": [{
      \"parts\": [
        {\"text\": \"YOUR EDIT INSTRUCTION HERE\"},
        {\"inline_data\": {\"mime_type\": \"image/png\", \"data\": \"${SOURCE_B64}\"}}
      ]
    }],
    \"generationConfig\": {
      \"responseModalities\": [\"TEXT\", \"IMAGE\"]
    }
  }"
```

**Decode response:**
```bash
echo "$response" | jq -r '[.candidates[0].content.parts[] | select(.inlineData)][0].inlineData.data' | base64 -d > output.png
```

### Edit instruction examples

| Task | Instruction |
|------|-------------|
| Color change | "Change the line color from gold to deep navy blue (#194B74). Keep everything else the same." |
| Dark mode | "Invert for dark mode: change white background to dark navy (#0F1419), make lines lighter gold." |
| Simplify | "Reduce detail — fewer lines, cleaner, simpler. Keep same shape and composition." |
| Background remove | "Remove the background, make it transparent. Keep the subject." |
| Style transfer | "Make this look like a watercolor painting. Keep the same composition." |

### Key differences from text-to-image

- Endpoint: `generateContent` (not `predict`)
- Model: `gemini-2.5-flash-image` (not `imagen-4.0-generate-001`)
- Input: `contents[].parts[]` with both `text` and `inline_data`
- Config: `responseModalities: ["TEXT", "IMAGE"]` required
- Response: `candidates[0].content.parts[]` — filter for `inlineData`

## Prompt Rules

1. **Cap description at 200 characters** — longer prompts degrade quality
2. **Cap keywords/tags at 5** — focus beats breadth
3. **Always append:** `No text, no logos, no faces` — prevents rendering artifacts
4. **Be specific about style** — "watercolor", "3D render", "flat illustration" yield very different results
5. **For edits, be specific about what to keep** — "Keep the same shape, composition, and level of detail"

## Prompt Templates

### Square (1:1) — icon, album cover, social card
```
Square album cover art for [SUBJECT]. Bold, vibrant, iconic.
Rich colors with warm gold accents. Abstract and evocative.
No text, no logos, no faces.
```

### Wide (16:9) — hero banner, header, OG image
```
Wide cinematic banner for [SUBJECT]. Warm atmospheric gradient,
subtle golden particle effects, professional and aspirational.
Wide cinematic composition. No text, no logos, no faces.
```

### Portrait (9:16) — story, mobile splash
```
Vertical composition for [SUBJECT]. Dramatic lighting,
rich depth of field, immersive atmosphere.
No text, no logos, no faces.
```

## Aspect Ratios

| Use Case | Ratio | Param |
|----------|-------|-------|
| Icon, social card, album cover | 1:1 | `"1:1"` |
| Hero banner, OG image | 16:9 | `"16:9"` |
| Story, mobile splash | 9:16 | `"9:16"` |
| Standard photo | 4:3 | `"4:3"` |
| Portrait photo | 3:4 | `"3:4"` |

## Listing Available Models

```bash
curl -s "https://generativelanguage.googleapis.com/v1beta/models?key=$GEMINI_API_KEY" \
  | jq -r '.models[] | select(.name | test("image|imagen")) | .name'
```

## Strengths & Limitations

**Gemini Imagen excels at:**
- Abstract, colorful, evocative imagery
- Brand art, album covers, promotional graphics
- Warm, atmospheric gradients and particle effects
- Iterative editing from a source image

**Use something else for:**
- Photorealistic scenes with specific people (use DALL-E or Midjourney)
- Images containing readable text (all models struggle, but DALL-E is better)
- Precise spatial layout requirements

## Pattern: Iterate, Don't Regenerate

When doing brand/logo work:

```
1. Generate initial candidates from text (Imagen 4, multiple prompts)
2. User picks a direction
3. ALL further iterations use image editing (Nano Banana) from the picked image
4. Never re-describe from text — you lose what they liked
```

## Pattern: Fire-and-Forget

Never block the main user flow on image generation. Generate async, display when ready.

```
User request → acknowledge → generate in background → present when done
```

---

*Related: `@content/youtube/wes-mcdowell/the-new-way-to-make-youtube-thumbnails-in-minutes-no-design-experience-needed` · `@content/youtube/sirio-berati/nano-banana-is-wild-officially-released` · `@content/youtube/sirio-berati/draw-to-edit-with-nano-banana-free-and-open-source-workflow` · `@content/youtube/sirio-berati/seedream-4-is-insane-12-wild-demos` · `@content/youtube/sirio-berati/i-built-a-6-node-ai-workflow-here-s-what-s-actually-happening`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*