nanobanana
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNano Banana - AI Image Generation
Nano Banana - AI图片生成
Generate and edit images using Google's Gemini 3 Pro Image model (, nicknamed "Nano Banana Pro" 🍌).
gemini-3-pro-image-preview使用Google的Gemini 3 Pro Image模型(,昵称“Nano Banana Pro”🍌)生成和编辑图片。
gemini-3-pro-image-previewPrerequisites
前提条件
Required:
- - Get from Google AI Studio
GEMINI_API_KEY - Python 3.10+ with package
google-genai
Install dependencies:
bash
pip install google-genai pillow必需项:
- - 从Google AI Studio获取
GEMINI_API_KEY - Python 3.10+ 及 包
google-genai
安装依赖:
bash
pip install google-genai pillowQuick Start
快速开始
Generate an image:
生成图片:
bash
python3 <skill_dir>/scripts/generate.py "a cute robot mascot, pixel art style" -o robot.pngbash
python3 <skill_dir>/scripts/generate.py "a cute robot mascot, pixel art style" -o robot.pngEdit an existing image:
编辑现有图片:
bash
python3 <skill_dir>/scripts/generate.py "make the background blue" -i input.jpg -o output.pngbash
python3 <skill_dir>/scripts/generate.py "make the background blue" -i input.jpg -o output.pngGenerate with specific aspect ratio:
按特定宽高比生成:
bash
python3 <skill_dir>/scripts/generate.py "cinematic landscape" --ratio 21:9 -o landscape.pngbash
python3 <skill_dir>/scripts/generate.py "cinematic landscape" --ratio 21:9 -o landscape.pngGenerate high-resolution 4K image:
生成高分辨率4K图片:
bash
python3 <skill_dir>/scripts/generate.py "professional product photo" --size 4K -o product.pngbash
python3 <skill_dir>/scripts/generate.py "professional product photo" --size 4K -o product.pngScript Reference
脚本参考
scripts/generate.py
scripts/generate.pyscripts/generate.py
scripts/generate.pyMain 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 outputSupported aspect ratios:
- - Square (default)
1:1 - ,
2:3- Portrait/Landscape3:2 - ,
3:4- Standard4:3 - ,
4:5- Photo5:4 - ,
9:16- Widescreen16:9 - - Ultra-wide/Cinematic
21:9
图片生成主脚本。
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.pyscripts/batch_generate.py
scripts/batch_generate.pyGenerate 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 logoPython 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_imageGenerate 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"
)
undefinedresult = edit_image(
prompt="add flying cars to the sky",
input_path="city.png",
output_path="city_edited.png"
)
undefinedEnvironment Variables
环境变量
| Variable | Description | Default |
|---|---|---|
| Google Gemini API key | Required |
| Default output directory | |
| 变量名 | 描述 | 默认值 |
|---|---|---|
| Google Gemini API密钥 | 必填 |
| 默认输出目录 | |
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 for factually accurate images involving:
--search- 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
批量生成技巧
- Generate 10-20 variations to explore options
- Use consistent prompts for style coherence
- Add 3-5 second delays to avoid rate limits
- Review results and iterate on best candidates
- 生成10-20个变体以探索更多选项
- 使用一致的提示词保证风格统一
- 添加3-5秒延迟以避免速率限制
- 查看结果并优化最佳候选
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 environment variable
GEMINI_API_KEY - Or pass via option
--api-key
"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/ - 使用示例脚本