Nano Banana Pro — Gemini Image Generation & Editing
Attribution: Sourced from steipete/agent-scripts by Peter Steinberger.
When to Use
- Generating images from text prompts via Gemini Flash Image API
- Editing existing images with targeted modifications
- Iterating on image prompts using the draft→iterate→final workflow
Generate new images or edit existing ones using Google's Gemini Flash Image API (Gemini 3.1 Flash Image).
Prerequisites
uvinstalled (brew install uv)GEMINI_API_KEYenvironment variable set
Usage
Generate new image:
uv run generate_image.py --prompt "your image description" --filename "output-name.png" [--resolution 512|1K|2K|4K] [--api-key KEY]
Edit existing image:
uv run generate_image.py --prompt "editing instructions" --filename "output-name.png" --input-image "path/to/input.png" [--resolution 512|1K|2K|4K]
Default Workflow (draft → iterate → final)
Goal: fast iteration without burning time on 4K until the prompt is correct.
Draft (1K): quick feedback loop
uv run generate_image.py --prompt "<draft prompt>" --filename "$(date +%Y-%m-%d-%H-%M-%S)-draft.png" --resolution 1KIterate: adjust prompt in small diffs; keep filename new per run.
Final (4K): only when prompt is locked
uv run generate_image.py --prompt "<final prompt>" --filename "$(date +%Y-%m-%d-%H-%M-%S)-final.png" --resolution 4K
Resolution Options
| Input | API Value |
|---|---|
| "thumbnail", "tiny", "512" | 512 |
| Default (no mention) | 1K |
| "1080p", "1K" | 1K |
| "2K", "2048", "medium" | 2K |
| "high-res", "4K", "ultra" | 4K |
Prompt Templates
Generation:
"Create an image of:
<subject>. Style:<style>. Composition:<camera/shot>. Lighting:<lighting>. Background:<background>. Color palette:<palette>. Avoid:<list>."
Editing (preserve everything else):
"Change ONLY:
<single change>. Keep identical: subject, composition/crop, pose, lighting, color palette, background, and overall style. Do not add new objects."
Preflight & Common Failures
# Preflight
command -v uv
echo ${GEMINI_API_KEY:0:5}... # show prefix only
Common failures:
Error: No API key provided.→ setGEMINI_API_KEYor pass--api-keyError loading input image:→ wrong path; verify--input-imagepoints to a real imagequota/permission/403→ wrong key, no access, or quota exceeded