Gemini Imagegen
Generate and edit images using Google Gemini's native image generation models (Nano...
Install
npx skills add dp-archive/archive --skill gemini-imagegen -g -a claude-code -y- Repository
- dp-archive/archive1.1k
- Category
- Media
- Updated
- 8mo ago
- License
- Apache-2.0
- Context cost
- Lightabout 1,280 tokens
- Runs scripts
- No, instructions only
What it does
Generate and edit images using Google Gemini's native image generation models (Nano Banana / Nano Banana Pro). Supports text-to-image, image editing with reference images, multi-image composition, and character consistency. Use when the user asks to generate images via Gemini, create AI illustrations, edit photos with Gemini, or needs high-quality image generation with the Google API. Requires GEMINI_API_KEY. Triggers: "generate image with gemini", "nano banana", "gemini image", "create illustration", "AI generate picture", "text to image".
Gemini Image Generation
Generate and edit images via Google Gemini's native multimodal image generation.
Model Selection
| Model ID | Codename | Best for | Max resolution |
|---|---|---|---|
gemini-2.5-flash-image | Nano Banana | Fast drafts, high-volume, low-latency | 1K |
gemini-3-pro-image-preview | Nano Banana Pro | Studio-quality, text rendering, complex prompts | 4K |
Default: gemini-3-pro-image-preview (Pro) unless speed/cost is a concern.
Setup
# Install (once)
# pip install google-genai
from google import genai
import os, base64
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
If GEMINI_API_KEY is missing, instruct the user to set it as an environment variable.
Never ask the user to paste the key in chat.
Text-to-Image
from google import genai
from google.genai import types
import os
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
response = client.models.generate_content(
model="gemini-3-pro-image-preview",
contents="A photorealistic cat on a rainbow sofa",
config=types.GenerateContentConfig(
response_modalities=["TEXT", "IMAGE"],
),
)
# Extract and save
for part in response.candidates[0].content.parts:
if part.inline_data is not None:
with open("output.png", "wb") as f:
f.write(part.inline_data.data)
break
Aspect Ratio
Set via image_config:
config=types.GenerateContentConfig(
response_modalities=["TEXT", "IMAGE"],
image_config=types.ImageConfig(
aspect_ratio="16:9", # for slides / widescreen
),
)
Supported ratios: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
Common choices:
- Slides / presentations →
16:9 - Social media / portraits →
9:16or4:5 - Square thumbnails →
1:1
Image Editing (with reference image)
from google.genai import types
from pathlib import Path
import base64


