Gemini Image Generation
Source: https://ai.google.dev/gemini-api/docs/image-generation
Google offers two approaches for image generation: Imagen (dedicated image model) and Gemini native (multimodal generation). All generated images include SynthID watermarks.
Model Selection
| Model |
API |
Use Case |
Output |
gemini-2.5-flash-image |
generate_content |
Fast text-to-image, editing, iteration |
Up to 4K |
gemini-3-pro-preview |
generate_content |
Best quality, complex compositions |
Up to 4K |
imagen-4.0-generate-001 |
generate_images |
High-fidelity text-to-image |
1K default |
imagen-4.0-ultra-generate-001 |
generate_images |
Ultra quality, 2K output |
Up to 2K |
imagen-4.0-fast-generate-001 |
generate_images |
Fast generation |
1K |
imagen-3.0-generate-002 |
generate_images |
Legacy, stable |
Up to 4 images |
When to use which:
- Gemini native (
gemini-*-image): Image editing, multi-turn refinement, mixed text+image output
- Imagen: Pure text-to-image, high-fidelity results, batch generation (1-4 images)
Quick Start
Gemini Native (Text-to-Image)
from google import genai
from PIL import Image
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=["A modern logo for a tech startup called 'Nexus'"],
)
for part in response.parts:
if part.inline_data is not None:
image = part.as_image()
image.save("logo.png")
Imagen (Dedicated Image Generation)
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_images(
model="imagen-4.0-generate-001",
prompt="A photorealistic sunset over mountains, 4K HDR",
config=types.GenerateImagesConfig(
number_of_images=4,
aspect_ratio="16:9",
)
)
for i, generated_image in enumerate(response.generated_images):
generated_image.image.save(f"sunset_{i}.png")
Image Editing (Gemini Native)
from google import genai
from PIL import Image
client = genai.Client()
source_image = Image.open("photo.jpg")
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=[
"Remove the background and replace with a gradient blue sky",
source_image,
],
)
for part in response.parts:
if part.inline_data is not None:
part.as_image().save("edited.png")
Best Practices
Prompt Structure
Build prompts with three components:
- Subject: The main object, person, or scene
- Context: Background, setting, environment
- Style: Art style, photography type, quality modifiers
"A [style] of [subject] in/with [context]"
Example:
"A minimalist logo for a health care company on a solid color background. Include the text 'Journey'."
Photography Modifiers
| Category |
Keywords |
| Proximity |
close-up, zoomed out, aerial, from below |
| Lighting |
natural, dramatic, warm, cold, golden hour |
| Camera |
motion blur, soft focus, bokeh, portrait |
| Lens |
35mm, 50mm, fisheye, wide angle, macro |
| Film |
black and white, polaroid, film noir |
| Quality |
4K, HDR, high-quality, professional |
Text in Images
When generating text in images:
- Keep text under 25 characters for best results
- Use 2-3 distinct phrases maximum
- Specify font style (bold, serif, sans-serif)
- Specify placement (top, center, bottom)
prompt = 'A poster with the text "Summerland" in bold font as a title, underneath is "Summer never felt so good"'
Aspect Ratios
| Ratio |
Use Case |
1:1 |
Social media posts, icons |
4:3 |
Photography, medium format |
3:4 |
Portrait, vertical scenes |
16:9 |
Widescreen, landscapes, presentations |
9:16 |
Mobile, stories, tall subjects |
Imagen Configuration
config = types.GenerateImagesConfig(
number_of_images=4, # 1-4 images
aspect_ratio="16:9", # Aspect ratio
image_size="2K", # 1K or 2K (Ultra/Standard only)
person_generation="allow_adult", # dont_allow, allow_adult, allow_all
)
Multi-Turn Refinement (Gemini Native)
Gemini native supports conversational image editing:
from google import genai
client = genai.Client()
chat = client.chats.create(model="gemini-2.5-flash-image")
# Initial generation
response = chat.send_message("Create a cozy coffee shop interior")
# Iterative refinement
response = chat.send_message("Add more plants and warmer lighting")
response = chat.send_message("Make it evening with fairy lights")
# Save final result
for part in response.parts:
if part.inline_data:
part.as_image().save("coffee_shop_final.png")
Async Usage
import asyncio
from google import genai
client = genai.Client()
async def generate_variations(prompt: str, count: int = 4):
"""Generate multiple image variations concurrently."""
tasks = [
client.aio.models.generate_images(
model="imagen-4.0-generate-001",
prompt=prompt,
config={"number_of_images": 1}
)
for _ in range(count)
]
results = await asyncio.gather(*tasks)
return [r.generated_images[0] for r in results]
Common Patterns
Logo Generation
prompt = """
A {style} logo for a {industry} company on a solid color background.
Include the text "{company_name}".
Style: minimalist, modern, clean lines
"""
Product Photography
prompt = """
Professional studio photo of {product},
{background} background,
{lighting} lighting,
4K, high detail, commercial quality
"""
Artistic Styles
Reference historical movements:
- "in the style of an impressionist painting"
- "in the style of pop art"
- "in the style of art deco poster"
- "digital art, trending on artstation"
Limitations
- Imagen: English prompts only, max 480 tokens
- Person generation:
allow_all not available in EU, UK, CH, MENA
- Text rendering: Best under 25 characters
- Iterative editing: Only with Gemini native, not Imagen
Documentation Index
| Resource |
When to Consult |
| gemini-image-generation.md |
Gemini native models, editing, multi-turn, grounding |
| imagen.md |
Imagen API, prompt guide, photography tips, model versions |
Syncing Documentation
cd skills/gemini-imagen
bun run scripts/sync-docs.ts
1---2name: gemini-imagen3description: Image generation with Google's Imagen and Gemini native models. Text-to-image, image editing, and iterative refinement.4---5
6# Gemini Image Generation
7
8> **Source:** https://ai.google.dev/gemini-api/docs/image-generation
9
10Google offers two approaches for image generation: **Imagen** (dedicated image model) and **Gemini native** (multimodal generation). All generated images include SynthID watermarks.
11
12## Model Selection
13
14| Model | API | Use Case | Output |
15|-------|-----|----------|--------|
16| `gemini-2.5-flash-image` | generate_content | Fast text-to-image, editing, iteration | Up to 4K |
17| `gemini-3-pro-preview` | generate_content | Best quality, complex compositions | Up to 4K |
18| `imagen-4.0-generate-001` | generate_images | High-fidelity text-to-image | 1K default |
19| `imagen-4.0-ultra-generate-001` | generate_images | Ultra quality, 2K output | Up to 2K |
20| `imagen-4.0-fast-generate-001` | generate_images | Fast generation | 1K |
21| `imagen-3.0-generate-002` | generate_images | Legacy, stable | Up to 4 images |
22
23**When to use which:**
24- **Gemini native** (`gemini-*-image`): Image editing, multi-turn refinement, mixed text+image output
25- **Imagen**: Pure text-to-image, high-fidelity results, batch generation (1-4 images)
26
27## Quick Start
28
29### Gemini Native (Text-to-Image)
30
31```python
32from google import genai
33from PIL import Image
34
35client = genai.Client()
36
37response = client.models.generate_content(
38 model="gemini-2.5-flash-image",
39 contents=["A modern logo for a tech startup called 'Nexus'"],
40)
41
42for part in response.parts:
43 if part.inline_data is not None:
44 image = part.as_image()
45 image.save("logo.png")
46```
47
48### Imagen (Dedicated Image Generation)
49
50```python
51from google import genai
52from google.genai import types
53
54client = genai.Client()
55
56response = client.models.generate_images(
57 model="imagen-4.0-generate-001",
58 prompt="A photorealistic sunset over mountains, 4K HDR",
59 config=types.GenerateImagesConfig(
60 number_of_images=4,
61 aspect_ratio="16:9",
62 )
63)
64
65for i, generated_image in enumerate(response.generated_images):
66 generated_image.image.save(f"sunset_{i}.png")
67```
68
69### Image Editing (Gemini Native)
70
71```python
72from google import genai
73from PIL import Image
74
75client = genai.Client()
76source_image = Image.open("photo.jpg")
77
78response = client.models.generate_content(
79 model="gemini-2.5-flash-image",
80 contents=[
81 "Remove the background and replace with a gradient blue sky",
82 source_image,
83 ],
84)
85
86for part in response.parts:
87 if part.inline_data is not None:
88 part.as_image().save("edited.png")
89```
90
91## Best Practices
92
93### Prompt Structure
94
95Build prompts with three components:
96
971. **Subject**: The main object, person, or scene
982. **Context**: Background, setting, environment
993. **Style**: Art style, photography type, quality modifiers
100
101```
102"A [style] of [subject] in/with [context]"
103```
104
105**Example:**
106```
107"A minimalist logo for a health care company on a solid color background. Include the text 'Journey'."
108```
109
110### Photography Modifiers
111
112| Category | Keywords |
113|----------|----------|
114| **Proximity** | close-up, zoomed out, aerial, from below |
115| **Lighting** | natural, dramatic, warm, cold, golden hour |
116| **Camera** | motion blur, soft focus, bokeh, portrait |
117| **Lens** | 35mm, 50mm, fisheye, wide angle, macro |
118| **Film** | black and white, polaroid, film noir |
119| **Quality** | 4K, HDR, high-quality, professional |
120
121### Text in Images
122
123When generating text in images:
124- Keep text **under 25 characters** for best results
125- Use **2-3 distinct phrases** maximum
126- Specify font style (bold, serif, sans-serif)
127- Specify placement (top, center, bottom)
128
129```python
130prompt = 'A poster with the text "Summerland" in bold font as a title, underneath is "Summer never felt so good"'
131```
132
133### Aspect Ratios
134
135| Ratio | Use Case |
136|-------|----------|
137| `1:1` | Social media posts, icons |
138| `4:3` | Photography, medium format |
139| `3:4` | Portrait, vertical scenes |
140| `16:9` | Widescreen, landscapes, presentations |
141| `9:16` | Mobile, stories, tall subjects |
142
143### Imagen Configuration
144
145```python
146config = types.GenerateImagesConfig(
147 number_of_images=4, # 1-4 images
148 aspect_ratio="16:9", # Aspect ratio
149 image_size="2K", # 1K or 2K (Ultra/Standard only)
150 person_generation="allow_adult", # dont_allow, allow_adult, allow_all
151)
152```
153
154## Multi-Turn Refinement (Gemini Native)
155
156Gemini native supports conversational image editing:
157
158```python
159from google import genai
160
161client = genai.Client()
162chat = client.chats.create(model="gemini-2.5-flash-image")
163
164# Initial generation
165response = chat.send_message("Create a cozy coffee shop interior")
166
167# Iterative refinement
168response = chat.send_message("Add more plants and warmer lighting")
169response = chat.send_message("Make it evening with fairy lights")
170
171# Save final result
172for part in response.parts:
173 if part.inline_data:
174 part.as_image().save("coffee_shop_final.png")
175```
176
177## Async Usage
178
179```python
180import asyncio
181from google import genai
182
183client = genai.Client()
184
185async def generate_variations(prompt: str, count: int = 4):
186 """Generate multiple image variations concurrently."""
187 tasks = [
188 client.aio.models.generate_images(
189 model="imagen-4.0-generate-001",
190 prompt=prompt,
191 config={"number_of_images": 1}
192 )
193 for _ in range(count)
194 ]
195 results = await asyncio.gather(*tasks)
196 return [r.generated_images[0] for r in results]
197```
198
199## Common Patterns
200
201### Logo Generation
202
203```python
204prompt = """
205A {style} logo for a {industry} company on a solid color background.
206Include the text "{company_name}".
207Style: minimalist, modern, clean lines
208"""
209```
210
211### Product Photography
212
213```python
214prompt = """
215Professional studio photo of {product},
216{background} background,
217{lighting} lighting,
2184K, high detail, commercial quality
219"""
220```
221
222### Artistic Styles
223
224Reference historical movements:
225- "in the style of an impressionist painting"
226- "in the style of pop art"
227- "in the style of art deco poster"
228- "digital art, trending on artstation"
229
230## Limitations
231
232- **Imagen**: English prompts only, max 480 tokens
233- **Person generation**: `allow_all` not available in EU, UK, CH, MENA
234- **Text rendering**: Best under 25 characters
235- **Iterative editing**: Only with Gemini native, not Imagen
236
237## Documentation Index
238
239| Resource | When to Consult |
240|----------|-----------------|
241| [gemini-image-generation.md](resources/gemini-image-generation.md) | Gemini native models, editing, multi-turn, grounding |
242| [imagen.md](resources/imagen.md) | Imagen API, prompt guide, photography tips, model versions |
243
244## Syncing Documentation
245
246```bash
247cd skills/gemini-imagen
248bun run scripts/sync-docs.ts
249```