运行时依赖
安装命令
点击复制技能文档
Nano Banana 2 Image Generation & Editing
生成 new images or edit existing ones using Google's Nano Banana 2 API (Gemini 3.1 Flash Image Preview).
Usage
运行 the script using absolute path (do NOT cd to 技能 directory first):
生成 new image:
uv 运行 ~/.codex/技能s/nano-banana-pro/scripts/生成_image.py --prompt "your image description" --filename "输出.png" [--模型 模型] [--resolution 512|1K|2K|4K] [--aspect-ratio RATIO] [--thinking-level minimal|high] [--image-only] [--API-key KEY]
Edit existing image:
uv 运行 ~/.codex/技能s/nano-banana-pro/scripts/生成_image.py --prompt "editing instructions" --filename "输出.png" --输入-image "path/to/输入.png" [--模型 模型] [--resolution 512|1K|2K|4K] [--aspect-ratio RATIO] [--API-key KEY]
Multiple 输入 images (up to 14):
uv 运行 ~/.codex/技能s/nano-banana-pro/scripts/生成_image.py --prompt "combine these elements" --filename "输出.png" --输入-image "img1.png" "img2.png" "img3.png" [--模型 模型] [--resolution 2K] [--API-key KEY]
导入ant: Always 运行 from the user's current working directory so images are saved where the user is working, not in the 技能 directory.
Default 工作流 (draft → iterate → final)
Goal: fast iteration without burning time on 4K until the prompt is correct.
Draft (1K): quick feedback loop uv 运行 ~/.codex/技能s/nano-banana-pro/scripts/生成_image.py --prompt "" --filename "yyyy-mm-dd-hh-mm-ss-draft.png" --resolution 1K Iterate: adjust prompt in small diffs; keep filename new per 运行 If editing: keep the same --输入-image for every iteration until you're h应用y. Final (4K): only when prompt is locked uv 运行 ~/.codex/技能s/nano-banana-pro/scripts/生成_image.py --prompt "" --filename "yyyy-mm-dd-hh-mm-ss-final.png" --resolution 4K 模型 Selection
Use --模型 to specify the Gemini 模型. Default: gemini-3.1-flash-image-preview.
AvAIlable 模型s:
模型 ID 别名 分辨率 宽高比 多图输入 Thinking Google 搜索 Grounding 特点 gemini-3.1-flash-image-preview Nano Banana 2 512 / 1K / 2K / 4K 14 种(含 1:4, 4:1, 1:8, 8:1) 最多 14 张(10 物体 + 4 角色) minimal / high 网页 搜索 + Image 搜索 速度/质量/成本最佳平衡,默认推荐 gemini-3-pro-image-preview Nano Banana Pro 1K / 2K / 4K 10 种 最多 11 张(6 物体 + 5 角色) 默认开启(不可关闭) 网页 搜索 专业素材制作,高级推理,高保真文字渲染 gemini-2.5-flash-image Nano Banana 仅 1K(1024px) 9 种 最多 3 张 不支持 不支持 最快最便宜,适合高并发低延迟场景
Map user 请求s:
Default / no preference → gemini-3.1-flash-image-preview "pro", "best 质量", "professional" → gemini-3-pro-image-preview "fast", "cheap", "basic" → gemini-2.5-flash-image Resolution Options
Gemini 3.1 Flash Image supports four resolutions (uppercase K required, except 512):
512 (0.5K) - ~512px resolution (fastest, lowest cost) 1K (default) - ~1024px resolution 2K - ~2048px resolution 4K - ~4096px resolution
Map user 请求s to API parameters:
No mention of resolution → 1K "thumbnAIl", "tiny", "preview", "0.5K", "512" → 512 "low resolution", "1080", "1080p", "1K" → 1K "2K", "2048", "normal", "medium resolution" → 2K "high resolution", "high-res", "hi-res", "4K", "ultra" → 4K Aspect Ratio Options
14 aspect ratios supported. Use --aspect-ratio to 设置:
1:1 - Square (default if no 输入 image) 1:4, 4:1 - Extreme vertical / horizontal (new in 3.1 Flash) 1:8, 8:1 - Ultra-extreme vertical / horizontal (new in 3.1 Flash) 2:3, 3:2 - Classic portrAIt / landscape 3:4, 4:3 - Standard photo portrAIt / landscape 4:5, 5:4 - Instagram-style portrAIt / landscape 9:16, 16:9 - Phone vertical / widescreen 21:9 - Ultra-widescreen / cinematic
Map user 请求s:
"square" → 1:1 "portrAIt", "vertical" → 3:4 or 9:16 "landscape", "horizontal" → 4:3 or 16:9 "widescreen", "cinematic" → 16:9 or 21:9 "phone", "story", "reel" → 9:16 "banner", "ultra-wide" → 21:9 "tall banner", "vertical banner" → 1:4 or 1:8 "horizontal banner" → 4:1 or 8:1
If no --aspect-ratio is specified, the 模型 defaults to matching the 输入 image's ratio, or 1:1 for text-to-image.
Thinking Level
Control the 模型's reasoning depth with --thinking-level:
minimal (default) - Fastest 响应, lowest latency high - Best 质量, 模型 reasons more deeply about composition
Use high for complex scenes, detAIled compositions, or when 质量 matters more than speed. The 模型 always uses some thinking internally; minimal just reduces it.
Multiple 输入 Images
Nano Banana 2 supports up to 14 reference images in a single 请求:
Up to 10 images of objects with high-fidelity Up to 4 images of characters for character consistency
Use cases:
Character consistency: Provide a character reference image, 生成 different poses/angles Composition: Combine elements from multiple images into one scene Style transfer: Provide a style reference + content image Product mockups: Place product on different backgrounds 360° views: 生成 different angles of a character by providing previous 输出s
Example:
uv 运行 ~/.codex/技能s/nano-banana-pro/scripts/生成_image.py \ --prompt "An office group photo of these peopl