nano-banana-pro-grsai

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Nano Banana Pro Image Generation & Editing

Nano Banana Pro 图片生成与编辑

Generate new images or edit existing ones using the grsai.com Nano Banana Pro API.
通过grsai.com的Nano Banana Pro API生成新图片或编辑现有图片。

Usage

使用方法

Run the script using absolute path (do NOT cd to skill directory first):
Generate new image:
bash
uv run scripts/generate_image.py --prompt "your image description" --filename "output-name.png" [--resolution 1K|2K|4K] [--api-key KEY]
Edit existing image:
bash
uv run scripts/generate_image.py --prompt "editing instructions" --filename "output-name.png" --input-image "path/to/input.png" [--resolution 1K|2K|4K] [--api-key KEY]
Important: Always run from the user's current working directory so images are saved where the user is working, not in the skill directory.
使用绝对路径运行脚本(请勿先切换到skill目录):
生成新图片:
bash
uv run scripts/generate_image.py --prompt "your image description" --filename "output-name.png" [--resolution 1K|2K|4K] [--api-key KEY]
编辑现有图片:
bash
uv run scripts/generate_image.py --prompt "editing instructions" --filename "output-name.png" --input-image "path/to/input.png" [--resolution 1K|2K|4K] [--api-key KEY]
重要提示: 始终从用户当前工作目录运行脚本,这样图片会保存到用户的工作目录,而非skill目录。

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 scripts/generate_image.py --prompt "<draft prompt>" --filename "yyyy-mm-dd-hh-mm-ss-draft.png" --resolution 1K
  • Iterate: adjust prompt in small diffs; keep filename new per run
    • If editing: keep the same
      --input-image
      for every iteration until you're happy.
  • Final (4K): only when prompt is locked
    • uv run scripts/generate_image.py --prompt "<final prompt>" --filename "yyyy-mm-dd-hh-mm-ss-final.png" --resolution 4K
目标:快速迭代,在确定prompt准确前无需花费时间生成4K图片。
  • 草稿(1K):快速反馈循环
    • uv run scripts/generate_image.py --prompt "<draft prompt>" --filename "yyyy-mm-dd-hh-mm-ss-draft.png" --resolution 1K
  • 迭代:小幅调整prompt;每次运行使用新文件名
    • 若为编辑操作:在满意前,每次迭代使用相同的
      --input-image
  • 最终版(4K):仅在prompt确定后使用
    • uv run scripts/generate_image.py --prompt "<final prompt>" --filename "yyyy-mm-dd-hh-mm-ss-final.png" --resolution 4K

Resolution Options

分辨率选项

  • 1K (default) - ~1024px resolution
  • 2K - ~2048px resolution
  • 4K - ~4096px resolution
Map user requests to API parameters:
  • No mention of resolution →
    1K
  • "low resolution", "1080", "1080p", "1K" →
    1K
  • "2K", "2048", "normal", "medium resolution" →
    2K
  • "high resolution", "high-res", "hi-res", "4K", "ultra" →
    4K
  • 1K(默认)- 约1024px分辨率
  • 2K - 约2048px分辨率
  • 4K - 约4096px分辨率
用户请求与API参数映射:
  • 未提及分辨率 →
    1K
  • “低分辨率”、“1080”、“1080p”、“1K” →
    1K
  • “2K”、“2048”、“普通”、“中等分辨率” →
    2K
  • “高分辨率”、“high-res”、“hi-res”、“4K”、“超清” →
    4K

Aspect Ratio Options

宽高比选项

Pass via
--aspect-ratio
. Supported values:
auto
(default),
1:1
,
16:9
,
9:16
,
4:3
,
3:4
,
3:2
,
2:3
,
5:4
,
4:5
,
21:9
通过
--aspect-ratio
参数传递。支持的值:
auto
(默认)、
1:1
16:9
9:16
4:3
3:4
3:2
2:3
5:4
4:5
21:9

API Key

API密钥

The script checks for API key in this order:
  1. --api-key
    argument (use if user provided key in chat)
  2. GRSAI_API_KEY
    environment variable
If neither is available, the script exits with an error message.
脚本按以下顺序检查API密钥:
  1. --api-key
    参数(若用户在对话中提供了密钥则使用)
  2. GRSAI_API_KEY
    环境变量
若两者均不可用,脚本将退出并显示错误信息。

Troubleshooting

故障排除

SymptomResolution
Error: No API key provided.
Set
GRSAI_API_KEY
env var or pass
--api-key
Error: Input image not found:
Wrong path or unreadable file; verify with
test -f "path"
HTTP 401Wrong or expired API key
Generation failed:
Content moderation or invalid input; rephrase prompt
uv: command not found
Install:
curl -LsSf https://astral.sh/uv/install.sh | sh
, then restart terminal
For transient errors (network timeouts, server errors), the script retries automatically with exponential backoff. If all retries fail, surface the error to the user.
症状解决方法
Error: No API key provided.
设置
GRSAI_API_KEY
环境变量或传递
--api-key
参数
Error: Input image not found:
路径错误或文件不可读;使用
test -f "path"
验证
HTTP 401API密钥错误或已过期
Generation failed:
内容审核不通过或输入无效;重新调整prompt
uv: command not found
安装:
curl -LsSf https://astral.sh/uv/install.sh | sh
,然后重启终端
对于临时错误(网络超时、服务器错误),脚本会自动使用指数退避策略重试。若所有重试均失败,将向用户显示错误信息。

Filename Generation

文件名生成

Generate filenames with the pattern:
yyyy-mm-dd-hh-mm-ss-name.png
Format:
{timestamp}-{descriptive-name}.png
  • Timestamp: Current date/time in format
    yyyy-mm-dd-hh-mm-ss
    (24-hour format)
  • Name: Descriptive lowercase text with hyphens
  • Keep the descriptive part concise (1-5 words typically)
  • Use context from user's prompt or conversation
  • If unclear, use random identifier (e.g.,
    x9k2
    ,
    a7b3
    )
Examples:
  • Prompt "A serene Japanese garden" →
    2025-11-23-14-23-05-japanese-garden.png
  • Prompt "sunset over mountains" →
    2025-11-23-15-30-12-sunset-mountains.png
  • Prompt "create an image of a robot" →
    2025-11-23-16-45-33-robot.png
  • Unclear context →
    2025-11-23-17-12-48-x9k2.png
按照以下格式生成文件名:
yyyy-mm-dd-hh-mm-ss-name.png
格式:
{时间戳}-{描述性名称}.png
  • 时间戳:当前日期/时间,格式为
    yyyy-mm-dd-hh-mm-ss
    (24小时制)
  • 名称:简洁的小写文本,用连字符分隔
  • 描述性部分保持简洁(通常1-5个词)
  • 参考用户prompt或对话上下文
  • 若上下文不明确,使用随机标识符(例如
    x9k2
    a7b3
示例:
  • Prompt "A serene Japanese garden" →
    2025-11-23-14-23-05-japanese-garden.png
  • Prompt "sunset over mountains" →
    2025-11-23-15-30-12-sunset-mountains.png
  • Prompt "create an image of a robot" →
    2025-11-23-16-45-33-robot.png
  • 上下文不明确 →
    2025-11-23-17-12-48-x9k2.png

Image Editing

图片编辑

When the user wants to modify an existing image:
  1. Check if they provide an image path or reference an image in the current directory
  2. Use
    --input-image
    parameter with the path to the image
  3. The prompt should contain editing instructions (e.g., "make the sky more dramatic", "remove the person", "change to cartoon style")
  4. Common editing tasks: add/remove elements, change style, adjust colors, blur background, etc.
当用户想要修改现有图片时:
  1. 检查用户是否提供了图片路径或引用了当前目录中的图片
  2. 使用
    --input-image
    参数传入图片路径
  3. Prompt应包含编辑指令(例如“让天空更有氛围感”、“移除人物”、“改为卡通风格”)
  4. 常见编辑任务:添加/移除元素、更改风格、调整颜色、模糊背景等

Prompt Handling

Prompt处理

For generation: Pass user's image description as-is to
--prompt
. Only rework if clearly insufficient.
For editing: Pass editing instructions in
--prompt
(e.g., "add a rainbow in the sky", "make it look like a watercolor painting")
Preserve user's creative intent in both cases.
生成图片: 将用户的图片描述直接传入
--prompt
。仅在描述明显不充分时进行调整。
编辑图片:
--prompt
中传入编辑指令(例如“在天空中添加彩虹”、“让它看起来像水彩画”)
两种情况均需保留用户的创意意图。

Prompt Templates (high hit-rate)

高成功率Prompt模板

Use templates when the user is vague or when edits must be precise.
  • Generation template:
    • "Create an image of: <subject>. Style: <style>. Composition: <camera/shot>. Lighting: <lighting>. Background: <background>. Color palette: <palette>. Avoid: <list>."
  • Editing template (preserve everything else):
    • "Change ONLY: <single change>. Keep identical: subject, composition/crop, pose, lighting, color palette, background, text, and overall style. Do not add new objects. If text exists, keep it unchanged."
当用户描述模糊或编辑需求需要精准时,使用模板。
  • 生成模板:
    • “Create an image of: <subject>. Style: <style>. Composition: <camera/shot>. Lighting: <lighting>. Background: <background>. Color palette: <palette>. Avoid: <list>."
  • 编辑模板(保留其他所有元素):
    • “Change ONLY: <single change>. Keep identical: subject, composition/crop, pose, lighting, color palette, background, text, and overall style. Do not add new objects. If text exists, keep it unchanged."

Output

输出

  • Saves image to current directory (or specified path if filename includes directory)
  • Script outputs the full path to the generated image
  • Do not read the image back - just inform the user of the saved path
  • 将图片保存到当前目录(若文件名包含目录,则保存到指定路径)
  • 脚本会输出生成图片的完整路径
  • 请勿读取生成的图片 - 只需告知用户保存路径即可

Examples

示例

Generate new image:
bash
uv run scripts/generate_image.py --prompt "A serene Japanese garden with cherry blossoms" --filename "2025-11-23-14-23-05-japanese-garden.png" --resolution 4K
Edit existing image:
bash
uv run scripts/generate_image.py --prompt "make the sky more dramatic with storm clouds" --filename "2025-11-23-14-25-30-dramatic-sky.png" --input-image "original-photo.jpg" --resolution 2K
生成新图片:
bash
uv run scripts/generate_image.py --prompt "A serene Japanese garden with cherry blossoms" --filename "2025-11-23-14-23-05-japanese-garden.png" --resolution 4K
编辑现有图片:
bash
uv run scripts/generate_image.py --prompt "make the sky more dramatic with storm clouds" --filename "2025-11-23-14-25-30-dramatic-sky.png" --input-image "original-photo.jpg" --resolution 2K