nano-banana-pro-image-gen
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese图片生成与编辑
Image Generation and Editing
图片生成技能,可以通过自然语言帮助用户生成图片,通过API易国内代理服务访问,支持Node.js和Python两种运行环境。
Image Generation Skill helps users generate images via natural language, accessible via APIYI domestic proxy service, and supports both Node.js and Python runtime environments.
使用指引
Usage Guide
遵循以下步骤:
Follow these steps:
第1步:分析需求与参数提取
Step 1: Requirement Analysis and Parameter Extraction
-
明确意图:区分用户是需要【文生图】(生成新图片)还是【图生图】(编辑/修改现有图片)。
-
提示词(Prompt)分析:
- 使用用户原始完整输入:把用户输入的原始完整问题需求描述(原文)直接作为 提示词的主体,避免自行改写、总结或二次创作,防止细节丢失。
-p - 需要补充时先确认:如果信息不足(例如缺少风格、主体数量、镜头语言、场景细节、文字内容、禁止元素等),先向用户提问确认;用户确认后,再把补充内容以“追加”的方式拼接到原始提示词后。
- 样例:
- 用户输入:“帮我生成一张猫的图片,风格要可爱一点。”
- 正例说明:直接使用用户输入作为提示词:
-p "帮我生成一张猫的图片,风格要可爱一点。" - 反例说明:擅自改写为“生成一张可爱风格的猫的图片”会丢失用户原始输入的细节和语气。
- 如果需要补充细节(例如颜色、背景等),先提问确认:“你希望猫是什么颜色的?背景有什么要求吗?”用户回答后,再追加到提示词中:
-p "帮我生成一张猫的图片,风格要可爱一点。猫是橘色的,背景是草地。"
- 使用用户原始完整输入:把用户输入的原始完整问题需求描述(原文)直接作为
-
关键参数整理:
- Prompt(必需):提示词分析后的最终提示词(默认=用户原始完整且一致的输入;仅在用户确认后才追加补充信息)。
- Filename(可选):输出图片文件名/路径(需包含文件随机标识,避免重复)。不传则脚本会自动生成带时间戳的文件名。建议根据内容生成合理文件名(例如 ),避免使用通用名。
cat_in_garden.png - Aspect Ratio(可选):根据用户描述推断比例。例如:
- "手机壁纸" ->
9:16 - "电脑壁纸/视频封面" ->
16:9 - "头像" ->
1:1 - 默认若用户未明确不指定图片比例,保持图片比例为空。
- "手机壁纸" ->
- Resolution(可选):
- 默认图片比例使用 。
2K - 仅在极端高清需求或用户指定时使用 ,并通过友好性提示,提示用户生成较慢,耐心等待。
4K - 注意:参数值必须大写(,
1K,2K)。4K
- 默认图片比例使用
-
Clarify Intent: Distinguish whether the user needs [Text-to-Image] (generate new images) or [Image-to-Image] (edit/modify existing images).
-
Prompt Analysis:
- Use the user's original complete input: Directly use the user's original full question and requirement description as the main body of the prompt. Avoid rewriting, summarizing, or secondary creation on your own to prevent loss of details.
-p - Confirm first before supplementing: If information is insufficient (e.g., missing style, number of subjects, shot language, scene details, text content, prohibited elements, etc.), ask the user for confirmation first; after the user confirms, append the supplementary content to the original prompt in an "appended" manner.
- Examples:
- User input: "Help me generate a picture of a cat, in a cute style."
- Correct example: Use the user's input directly as the prompt:
-p "Help me generate a picture of a cat, in a cute style." - Incorrect example: Unauthorized rewriting to "Generate a picture of a cat in cute style" will lose the details and tone of the user's original input.
- If details need to be supplemented (e.g., color, background, etc.), ask for confirmation first: "What color do you want the cat to be? Any requirements for the background?" After the user replies, append to the prompt:
-p "Help me generate a picture of a cat, in a cute style. The cat is orange, and the background is grass."
- Use the user's original complete input: Directly use the user's original full question and requirement description as the main body of the
-
Key Parameter Organization:
- Prompt (Required): The final prompt after analysis (default = the user's original complete and consistent input; only append supplementary information after user confirmation).
- Filename (Optional): Output image filename/path (must include a random identifier to avoid duplicates). If not provided, the script will automatically generate a filename with a timestamp. It is recommended to generate a reasonable filename based on content (e.g., ), avoid using generic names.
cat_in_garden.png - Aspect Ratio (Optional): Infer the ratio based on the user's description. For example:
- "Mobile wallpaper" ->
9:16 - "Computer wallpaper/video cover" ->
16:9 - "Avatar" ->
1:1 - Default: If the user does not specify an aspect ratio, leave it empty.
- "Mobile wallpaper" ->
- Resolution (Optional):
- Default aspect ratio uses .
2K - Only use for extreme high-definition needs or when specified by the user, and prompt the user friendly that generation will be slow, please wait patiently.
4K - Note: Parameter values must be uppercase (,
1K,2K).4K
- Default aspect ratio uses
第2步:环境检查与命令执行
Step 2: Environment Check and Command Execution
-
检查环境:确认环境变量是否已设置(通常假定已设置,若运行失败再提示用户)。
APIYI_API_KEY -
构建并运行命令:
- 优先尝试 Node.js 版本:如果环境有 Node(命令可用),优先使用
node(零依赖,参数与 Python 保持一致)。scripts/generate_image.js - Node 不可用再用 Python 版本:使用 。
scripts/generate_image.py
文生图命令模板(优先 Node.js):bashnode scripts/generate_image.js -p "{prompt}" -f "{filename}" [-a {ratio}] [-r {res}]图生图命令模板(优先 Node.js):bashnode scripts/generate_image.js -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-r {res}](可选)Python 版本命令模板(Node 不可用时):bashpython scripts/generate_image.py -p "{prompt}" -f "{filename}" [-a {ratio}] [-r {res}] python scripts/generate_image.py -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-r {res}] - 优先尝试 Node.js 版本:如果环境有 Node(
-
Check Environment: Confirm whether theenvironment variable is set (usually assumed to be set; prompt the user if execution fails).
APIYI_API_KEY -
Build and Run Commands:
- Priority: Node.js Version: If Node is available in the environment (the command works), prefer using
node(zero dependencies, parameters consistent with Python).scripts/generate_image.js - Use Python Version if Node is Unavailable: Use .
scripts/generate_image.py
Text-to-Image Command Template (Priority: Node.js):bashnode scripts/generate_image.js -p "{prompt}" -f "{filename}" [-a {ratio}] [-r {res}]Image-to-Image Command Template (Priority: Node.js):bashnode scripts/generate_image.js -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-r {res}](Optional) Python Version Command Template (When Node is Unavailable):bashpython scripts/generate_image.py -p "{prompt}" -f "{filename}" [-a {ratio}] [-r {res}] python scripts/generate_image.py -p "{edit_instruction}" -i "{input_path}" -f "{output_filename}" [-r {res}] - Priority: Node.js Version: If Node is available in the environment (the
⏱️ 长时间任务处理策略
⏱️ Long-running Task Handling Strategy
1. 任务前提示
1. Pre-task Prompt
执行前必须告知用户:
- "图片生成已启动,预计需要25秒到5分钟"
Must inform the user before execution:
- "Image generation has started, expected to take 25 seconds to 5 minutes"
2. 🎨 最佳实践示例
2. 🎨 Best Practice Examples
- 快速生成场景(1K分辨率)
"快速模式:1K分辨率生成,预计30秒内完成"
- 高质量生成场景(2K/4K分辨率)
"高质量模式:2K分辨率生成,预计1-4分钟\n⏳ 开始生成... 🔄"
- Quick Generation Scenario (1K Resolution)
"Quick Mode: Generate with 1K resolution, expected to complete within 30 seconds"
- High-quality Generation Scenario (2K/4K Resolution)
"High-quality Mode: Generate with 2K resolution, expected to take 1-4 minutes\n⏳ Starting generation... 🔄"
第3步:结果反馈
Step 3: Result Feedback
- 执行反馈:等待终端命令执行完毕。
- 成功:告知用户图片已生成,并指出保存路径。
- 失败:
- 若提示 API Key 缺失,请指导用户设置环境变量。
- 若提示网络错误,建议用户检查网络或稍后重试。
- Execution Feedback: Wait for the terminal command to complete execution.
- Success: Inform the user that the image has been generated and indicate the save path.
- Failure:
- If prompted for missing API Key, guide the user to set the environment variable.
- If prompted for network error, suggest the user check the network or try again later.
命令行使用样例
Command Line Usage Examples
生成新图片
Generate New Images
bash
python scripts/generate_image.py -p "图片描述文本" -f "output.png" [-a 1:1] [-r 1K]示例:
bash
undefinedbash
python scripts/generate_image.py -p "Image description text" -f "output.png" [-a 1:1] [-r 1K]Example:
bash
undefined基础生成
Basic generation
python scripts/generate_image.py -p "一只可爱的橘猫在草地上玩耍" -f "cat.png"
python scripts/generate_image.py -p "A cute orange cat playing on the grass" -f "cat.png"
指定比例和分辨率
Specify aspect ratio and resolution
python scripts/generate_image.py -p "日落山脉风景" -f "sunset.png" -a 16:9 -r 4K
python scripts/generate_image.py -p "Sunset mountain landscape" -f "sunset.png" -a 16:9 -r 4K
竖版高清图片(适合手机壁纸)
Vertical high-definition image (suitable for mobile wallpaper)
python scripts/generate_image.py -p "城市夜景" -f "city.png" -a 9:16 -r 2K
**(可选)Node.js 版本示例:**
```bashpython scripts/generate_image.py -p "City night view" -f "city.png" -a 9:16 -r 2K
**(Optional) Node.js Version Example**:
```bash基础生成
Basic generation
node scripts/generate_image.js -p "一只可爱的橘猫在草地上玩耍" -f "cat.png"
node scripts/generate_image.js -p "A cute orange cat playing on the grass" -f "cat.png"
指定比例和分辨率
Specify aspect ratio and resolution
node scripts/generate_image.js -p "日落山脉风景" -f "sunset.png" -a 16:9 -r 4K
undefinednode scripts/generate_image.js -p "Sunset mountain landscape" -f "sunset.png" -a 16:9 -r 4K
undefined编辑已有图片
Edit Existing Images
bash
python scripts/generate_image.py -p "编辑指令" -f "output.png" -i "path/to/input.png" [-a 1:1] [-r 1K]示例:
bash
undefinedbash
python scripts/generate_image.py -p "Editing instruction" -f "output.png" -i "path/to/input.png" [-a 1:1] [-r 1K]Example:
bash
undefined修改风格
Modify style
python scripts/generate_image.py -p "将图片转换成水彩画风格" -f "watercolor.png" -i "original.png"
python scripts/generate_image.py -p "Convert the image to watercolor style" -f "watercolor.png" -i "original.png"
添加元素
Add elements
python scripts/generate_image.py -p "在天空添加彩虹" -f "rainbow.png" -i "landscape.png" -r 2K
python scripts/generate_image.py -p "Add a rainbow to the sky" -f "rainbow.png" -i "landscape.png" -r 2K
替换背景
Replace background
python scripts/generate_image.py -p "将背景换成海滩" -f "beach-bg.png" -i "portrait.png" -a 3:4
**(可选)Node.js 版本示例:**
```bashpython scripts/generate_image.py -p "Change the background to a beach" -f "beach-bg.png" -i "portrait.png" -a 3:4
**(Optional) Node.js Version Example**:
```bash修改风格
Modify style
node scripts/generate_image.js -p "将图片转换成水彩画风格" -f "watercolor.png" -i "original.png"
node scripts/generate_image.js -p "Convert the image to watercolor style" -f "watercolor.png" -i "original.png"
多张参考图(最多14张)
Multiple reference images (up to 14)
node scripts/generate_image.js -p "参考多张图片融合风格" -i ref1.png ref2.png ref3.png -f "merged.png"
undefinednode scripts/generate_image.js -p "Fuse styles by referencing multiple images" -i ref1.png ref2.png ref3.png -f "merged.png"
undefined附加资源
Additional Resources
- 常见使用场景文档:references/scene.md
- Common Usage Scenarios Document: references/scene.md
命令行参数说明
Command Line Parameter Description
Python 与 Node.js 版本参数保持一致(短参数与长参数等价)。
| 参数 | 必填 | 说明 |
|---|---|---|
| 是 | 图片描述(文生图)或编辑指令(图生图)。保留用户原始完整输入。 |
| 否 | 输出图片路径/文件名;不传则自动生成带时间戳的 PNG 文件名,并写入当前目录。 |
| 否 | 图片比例: |
| 否 | 图片分辨率: |
| 否 | 图生图输入图片路径;可传多张(最多 14 张)。传入该参数即进入编辑模式。 |
Parameters for Python and Node.js versions are consistent (short parameters are equivalent to long parameters).
| Parameter | Required | Description |
|---|---|---|
| Yes | Image description (text-to-image) or editing instruction (image-to-image). Keep the user's original complete input. |
| No | Output image path/filename; if not provided, a PNG filename with timestamp will be automatically generated and saved to the current directory. |
| No | Image aspect ratio: |
| No | Image resolution: |
| No | Input image path for image-to-image; multiple images can be passed (up to 14). Passing this parameter enters edit mode. |
图片参数说明
Image Parameter Description
aspect_ratio - 图片比例
aspect_ratio - Image Aspect Ratio
支持以下10种比例:
| 比例 | 方向 | 适用场景 |
|---|---|---|
| 1:1 | 正方形 | 头像、Instagram帖子 |
| 16:9 | 横版 | YouTube缩略图、桌面壁纸、演示文稿 |
| 9:16 | 竖版 | 抖音/TikTok、Instagram Stories、手机壁纸 |
| 4:3 | 横版 | 经典照片、演示文稿 |
| 3:4 | 竖版 | Pinterest、人像摄影 |
| 3:2 | 横版 | 单反相机标准、印刷媒体 |
| 2:3 | 竖版 | 人像海报 |
| 5:4 | 横版 | 大幅面打印、艺术印刷 |
| 4:5 | 竖版 | Instagram帖子、社交媒体 |
| 21:9 | 超宽 | 电影感、横幅、全景 |
Supports the following 10 ratios:
| Aspect Ratio | Orientation | Applicable Scenario |
|---|---|---|
| 1:1 | Square | Avatars, Instagram posts |
| 16:9 | Landscape | YouTube thumbnails, desktop wallpapers, presentations |
| 9:16 | Portrait | Douyin/TikTok, Instagram Stories, mobile wallpapers |
| 4:3 | Landscape | Classic photos, presentations |
| 3:4 | Portrait | Pinterest, portrait photography |
| 3:2 | Landscape | DSLR standard, print media |
| 2:3 | Portrait | Portrait posters |
| 5:4 | Landscape | Large-format printing, art printing |
| 4:5 | Portrait | Instagram posts, social media |
| 21:9 | Ultra-wide | Cinematic feel, banners, panoramas |
resolution - 图片分辨率
resolution - Image Resolution
1K、2K、4K三种分辨率选项
注意: 分辨率值必须大写(1K、2K、4K)
默认: 2K
Three resolution options: 1K, 2K, 4K
Note: Resolution values must be uppercase (1K, 2K, 4K)
Default: 2K
注意事项
Notes
- API密钥必须设置,可通过环境变量或命令行参数提供
- 分辨率参数必须大写(1K/2K/4K),小写会默认使用1K
- 图片生成时间:25秒到5分钟不等,取决于分辨率和服务器负载
- 编辑图片时,输入图片会自动转换为base64编码
- 确保输出目录有写入权限
- API Key must be set, which can be provided via environment variable or command line parameter
- Resolution parameters must be uppercase (1K/2K/4K); lowercase will default to 1K
- Image generation time: 25 seconds to 5 minutes, depending on resolution and server load
- When editing images, the input image will be automatically converted to base64 encoding
- Ensure the output directory has write permission
API Key设置与获取
API Key Setup and Acquisition
如何获取API Key
How to Get an API Key
如果你还没有API密钥,请前往 https://api.apiyi.com 注册账号并申请API Key。
获取步骤:
- 访问 https://api.apiyi.com
- 注册/登录你的账号
- 在控制台中创建API密钥
- 复制密钥并设置环境变量或在命令行中使用
If you don't have an API Key yet, please visit https://api.apiyi.com to register an account and apply for an API Key.
Acquisition Steps:
- Visit https://api.apiyi.com
- Register/Log in to your account
- Create an API Key in the console
- Copy the key and set the environment variable or use it in the command line
设置API Key
Set Up API Key
脚本按以下顺序查找API密钥:
- 命令行参数(临时使用)
--api-key - 环境变量(推荐)
APIYI_API_KEY
设置环境变量(推荐):
bash
undefinedThe script looks for the API Key in the following order:
- command line parameter (temporary use)
--api-key - environment variable (recommended)
APIYI_API_KEY
Set Environment Variable (Recommended):
bash
undefinedLinux/Mac
Linux/Mac
export APIYI_API_KEY="your-api-key-here"
export APIYI_API_KEY="your-api-key-here"
Windows CMD
Windows CMD
我的电脑高级设置中设置环境变量或者执行set APIYI_API_KEY=your-api-key-here
Set the environment variable in Advanced System Settings of My Computer or execute set APIYI_API_KEY=your-api-key-here
Windows PowerShell
Windows PowerShell
在我的电脑中设置环境变量:$env:APIYI_API_KEY="your-api-key-here"
**命令行参数方式(临时):**
```bash
python scripts/generate_image.py -p "一只猫" -k "your-api-key-here"Set the environment variable in My Computer: $env:APIYI_API_KEY="your-api-key-here"
**Command Line Parameter Method (Temporary)**:
```bash
python scripts/generate_image.py -p "A cat" -k "your-api-key-here"作者介绍
About the Author
- 爱海贼的无处不在
- 我的微信公众号:无处不在的技术
- Everywhere Who Loves One Piece
- My WeChat Official Account: Ubiquitous Technology