nanobanana

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Nano Banana - AI Image Generation

Nano Banana - AI图片生成

Generate and edit images using Google's Gemini 3 Pro Image model (
gemini-3-pro-image-preview
, nicknamed "Nano Banana Pro" 🍌).
使用Google的Gemini 3 Pro Image模型(
gemini-3-pro-image-preview
,昵称“Nano Banana Pro”🍌)生成和编辑图片。

Prerequisites

前提条件

Required:
  • GEMINI_API_KEY
    - Get from Google AI Studio
  • Python 3.10+ with
    google-genai
    package
Install dependencies:
bash
pip install google-genai pillow
必需项:
安装依赖:
bash
pip install google-genai pillow

Quick Start

快速开始

Generate an image:

生成图片:

bash
python3 <skill_dir>/scripts/generate.py "a cute robot mascot, pixel art style" -o robot.png
bash
python3 <skill_dir>/scripts/generate.py "a cute robot mascot, pixel art style" -o robot.png

Edit an existing image:

编辑现有图片:

bash
python3 <skill_dir>/scripts/generate.py "make the background blue" -i input.jpg -o output.png
bash
python3 <skill_dir>/scripts/generate.py "make the background blue" -i input.jpg -o output.png

Generate with specific aspect ratio:

按特定宽高比生成:

bash
python3 <skill_dir>/scripts/generate.py "cinematic landscape" --ratio 21:9 -o landscape.png
bash
python3 <skill_dir>/scripts/generate.py "cinematic landscape" --ratio 21:9 -o landscape.png

Generate high-resolution 4K image:

生成高分辨率4K图片:

bash
python3 <skill_dir>/scripts/generate.py "professional product photo" --size 4K -o product.png
bash
python3 <skill_dir>/scripts/generate.py "professional product photo" --size 4K -o product.png

Script Reference

脚本参考

scripts/generate.py

scripts/generate.py

Main image generation script.
Usage: generate.py [OPTIONS] PROMPT

Arguments:
  PROMPT              Text prompt for image generation

Options:
  -o, --output PATH   Output file path (default: auto-generated)
  -i, --input PATH    Input image for editing (optional)
  -r, --ratio RATIO   Aspect ratio (1:1, 16:9, 9:16, 21:9, etc.)
  -s, --size SIZE     Image size: 2K or 4K (default: standard)
  --search            Enable Google Search grounding for accuracy
  -v, --verbose       Show detailed output
Supported aspect ratios:
  • 1:1
    - Square (default)
  • 2:3
    ,
    3:2
    - Portrait/Landscape
  • 3:4
    ,
    4:3
    - Standard
  • 4:5
    ,
    5:4
    - Photo
  • 9:16
    ,
    16:9
    - Widescreen
  • 21:9
    - Ultra-wide/Cinematic
图片生成主脚本。
Usage: generate.py [OPTIONS] PROMPT

Arguments:
  PROMPT              图片生成的文本提示词

Options:
  -o, --output PATH   输出文件路径(默认:自动生成)
  -i, --input PATH    用于编辑的输入图片(可选)
  -r, --ratio RATIO   宽高比(1:1, 16:9, 9:16, 21:9等)
  -s, --size SIZE     图片尺寸:2K或4K(默认:标准)
  --search            启用Google搜索 grounding 以提升准确性
  -v, --verbose       显示详细输出
支持的宽高比:
  • 1:1
    - 正方形(默认)
  • 2:3
    ,
    3:2
    - 竖屏/横屏
  • 3:4
    ,
    4:3
    - 标准比例
  • 4:5
    ,
    5:4
    - 照片比例
  • 9:16
    ,
    16:9
    - 宽屏
  • 21:9
    - 超宽屏/电影比例

scripts/batch_generate.py

scripts/batch_generate.py

Generate multiple images with sequential naming.
Usage: batch_generate.py [OPTIONS] PROMPT

Arguments:
  PROMPT              Text prompt for image generation

Options:
  -n, --count N       Number of images to generate (default: 10)
  -d, --dir PATH      Output directory
  -p, --prefix STR    Filename prefix (default: "image")
  -r, --ratio RATIO   Aspect ratio
  -s, --size SIZE     Image size (2K/4K)
  --delay SECONDS     Delay between generations (default: 3)
Example:
bash
python3 <skill_dir>/scripts/batch_generate.py "pixel art logo" -n 20 -d ./logos -p logo
按序列命名批量生成多张图片。
Usage: batch_generate.py [OPTIONS] PROMPT

Arguments:
  PROMPT              图片生成的文本提示词

Options:
  -n, --count N       生成图片数量(默认:10)
  -d, --dir PATH      输出目录
  -p, --prefix STR    文件名前缀(默认:"image")
  -r, --ratio RATIO   宽高比
  -s, --size SIZE     图片尺寸(2K/4K)
  --delay SECONDS     生成间隔延迟(默认:3)
示例:
bash
python3 <skill_dir>/scripts/batch_generate.py "pixel art logo" -n 20 -d ./logos -p logo

Python API

Python API

You can also use the module directly:
python
from generate import generate_image, edit_image
你也可以直接调用模块:
python
from generate import generate_image, edit_image

Generate image

生成图片

result = generate_image( prompt="a futuristic city at night", output_path="city.png", aspect_ratio="16:9", image_size="4K" )
result = generate_image( prompt="a futuristic city at night", output_path="city.png", aspect_ratio="16:9", image_size="4K" )

Edit existing image

编辑现有图片

result = edit_image( prompt="add flying cars to the sky", input_path="city.png", output_path="city_edited.png" )
undefined
result = edit_image( prompt="add flying cars to the sky", input_path="city.png", output_path="city_edited.png" )
undefined

Environment Variables

环境变量

VariableDescriptionDefault
GEMINI_API_KEY
Google Gemini API keyRequired
IMAGE_OUTPUT_DIR
Default output directory
./nanobanana-images
变量名描述默认值
GEMINI_API_KEY
Google Gemini API密钥必填
IMAGE_OUTPUT_DIR
默认输出目录
./nanobanana-images

Features

功能特性

Text-to-Image Generation

文本转图片生成

Create images from text descriptions. The model excels at:
  • Photorealistic images
  • Artistic styles (pixel art, illustration, etc.)
  • Product photography
  • Landscapes and scenes
根据文本描述创建图片。该模型擅长:
  • 写实风格图片
  • 艺术风格(像素画、插画等)
  • 产品摄影
  • 风景与场景

Image Editing

图片编辑

Transform existing images with natural language:
  • Style transfer
  • Object addition/removal
  • Background changes
  • Color adjustments
用自然语言转换现有图片:
  • 风格迁移
  • 对象添加/移除
  • 背景修改
  • 色彩调整

High-Resolution Output

高分辨率输出

  • Standard: Fast generation, good quality
  • 2K: Enhanced detail (2048px)
  • 4K: Maximum quality (3840px), best for text rendering
  • 标准:生成速度快,质量良好
  • 2K:细节增强(2048像素)
  • 4K:最高质量(3840像素),最适合文本渲染

Google Search Grounding

Google搜索 grounding

Enable
--search
for factually accurate images involving:
  • Real people, places, landmarks
  • Current events
  • Specific products or brands
启用
--search
选项,可生成涉及以下内容的事实准确图片:
  • 真实人物、地点、地标
  • 当前事件
  • 特定产品或品牌

Best Practices

最佳实践

Prompt Writing

提示词撰写

Good prompts include:
  • Subject description
  • Style/aesthetic
  • Lighting and mood
  • Composition details
  • Color palette
Example:
"A cozy coffee shop interior, warm lighting, vintage aesthetic, 
wooden furniture, plants on shelves, morning sunlight through windows, 
soft focus background, 35mm film photography style"
优质提示词包含:
  • 主体描述
  • 风格/美学
  • 光线与氛围
  • 构图细节
  • 调色板
示例:
"A cozy coffee shop interior, warm lighting, vintage aesthetic, 
wooden furniture, plants on shelves, morning sunlight through windows, 
soft focus background, 35mm film photography style"

Batch Generation Tips

批量生成技巧

  1. Generate 10-20 variations to explore options
  2. Use consistent prompts for style coherence
  3. Add 3-5 second delays to avoid rate limits
  4. Review results and iterate on best candidates
  1. 生成10-20个变体以探索更多选项
  2. 使用一致的提示词保证风格统一
  3. 添加3-5秒延迟以避免速率限制
  4. 查看结果并优化最佳候选

Rate Limits

速率限制

  • Gemini API has usage quotas
  • Add delays between batch generations
  • Check your quota at Google AI Studio
  • Gemini API有使用配额
  • 批量生成之间添加延迟
  • Google AI Studio查看你的配额

Troubleshooting

故障排除

"API key not found"
  • Set
    GEMINI_API_KEY
    environment variable
  • Or pass via
    --api-key
    option
"No image in response"
  • Prompt may have triggered safety filters
  • Try rephrasing to avoid sensitive content
"Rate limit exceeded"
  • Wait a few seconds and retry
  • Reduce batch size or add longer delays
“API key not found”
  • 设置
    GEMINI_API_KEY
    环境变量
  • 或通过
    --api-key
    选项传入
“No image in response”
  • 提示词可能触发了安全过滤器
  • 尝试重新措辞以避免敏感内容
“Rate limit exceeded”
  • 等待几秒后重试
  • 减少批量大小或延长延迟时间

References

参考资料

  • references/prompts.md - Prompt examples by category
  • examples/ - Example usage scripts
  • references/prompts.md - 按分类整理的提示词示例
  • examples/ - 使用示例脚本