Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

docs(image-gen): 更新 Nano Banana 工具的使用说明与参数示例

hugohe3df4015337e8b
diff --git a/roles/Image_Generator.md b/roles/Image_Generator.md
index 6d589a9e..e969b2ca 100644
--- a/roles/Image_Generator.md
+++ b/roles/Image_Generator.md
@@ -198,6 +198,7 @@ clean negative space in center for text overlay,
16:9 aspect ratio, high resolution, professional presentation background
```
+
**负面提示词**: `text, letters, watermark, faces, busy patterns, high contrast details`
---
@@ -232,6 +233,7 @@ color grading with cool blue tones (#1E3A5F),
high quality, sharp focus, 8K resolution, diverse professional team
```
+
**负面提示词**: `watermark, text overlay, artificial, CGI, illustration, cartoon, distorted faces`
---
@@ -267,6 +269,7 @@ color palette: blue (#4A90D9), coral (#FF6B6B), white,
white background, professional business illustration
```
+
**负面提示词**: `realistic, photography, 3D render, complex textures, gradients, watermark`
---
@@ -302,6 +305,7 @@ blue (#4A90D9) and gray (#6B7280) color scheme,
white background, clear labels, suitable for academic publication
```
+
**负面提示词**: `cluttered, messy, overlapping elements, dark background, realistic, photography`
---
@@ -335,6 +339,7 @@ minimalist style, gold (#D4AF37) on transparent background,
subtle and elegant, suitable for presentation slide corners
```
+
**负面提示词**: `busy, cluttered, high contrast, distracting, photorealistic`
---
@@ -369,17 +374,27 @@ subtle and elegant, suitable for presentation slide corners
- 首次使用需配置:复制 `tools/nano_banana_config.example.json` 为 `tools/nano_banana_config.json`,填入 API Key
- 命令格式:
```bash
- python tools/nano_banana_gen.py "你的提示词" --aspect_ratio 16:9 --image_size 4K --output 项目/images
+ python tools/nano_banana_gen.py "你的提示词" --aspect_ratio 16:9 --image_size 4K --output 项目/images --filename cover_bg
```
+- **完整参数列表**:
+
+ | 参数 | 简写 | 说明 | 默认值 |
+ |------|------|------|--------|
+ | `prompt` | - | 正向提示词(位置参数) | `Nano Banana` |
+ | `--negative_prompt` | `-n` | 负面提示词,指定需要排除的元素 | 无 |
+ | `--aspect_ratio` | - | 图片宽高比 | `1:1` |
+ | `--image_size` | - | 图片尺寸 (`1K`, `2K`, `4K`) | `4K` |
+ | `--output` | `-o` | 输出目录 | 当前目录 |
+ | `--filename` | `-f` | 指定输出文件名(不含扩展名) | 自动命名 |
+
- 支持的宽高比: `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9`
- 支持的尺寸: `1K`, `2K`, `4K`(默认)
- 使用 `--output` 或 `-o` 参数指定输出目录,图片将保存到与 `image_prompts.md` 相同的 `images/` 目录
-**方式二:手动生成**(使用其他 AI 平台)
+**方式二:自动生成**(如果 AI 工具支持)
-- 提示词已保存在 `images/image_prompts.md`,告知用户文件位置
-- 用户自行到 AI 平台(Midjourney、DALL-E、Stable Diffusion、文心一格、通义万相)生成
-- 用户将生成的图片放入 `项目/images/` 目录
+- 直接调用图像生成 API
+- 下载并保存到 `项目/images/` 目录
**方式三:使用 Gemini 网页版**
@@ -390,10 +405,11 @@ subtle and elegant, suitable for presentation slide corners
- 或使用 [gemini-watermark-remover](https://github.com/journey-ad/gemini-watermark-remover)
- 将处理后的图片放入 `项目/images/` 目录
-**方式四:自动生成**(如果 AI 工具支持)
+**方式四:手动生成**(使用其他 AI 平台)
-- 直接调用图像生成 API
-- 下载并保存到 `项目/images/` 目录
+- 提示词已保存在 `images/image_prompts.md`,告知用户文件位置
+- 用户自行到 AI 平台(Midjourney、DALL-E、Stable Diffusion、文心一格、通义万相)生成
+- 用户将生成的图片放入 `项目/images/` 目录
### 4.4 验证阶段
@@ -449,13 +465,6 @@ high quality 4K, professional presentation background
```
-**负面提示词 (Negative Prompt)**:
-```
-
-text, letters, watermark, faces, busy patterns, high contrast details, low quality
-
-```
-
**图片描述 (Alt Text)**:
> 现代科技感抽象背景,深蓝色渐变配合数字波浪和粒子效果
@@ -497,6 +506,9 @@ text, letters, watermark, faces, busy patterns, high contrast details, low quali
**下一步**: 切换到 Executor 角色开始生成 SVG
```
+---
+
+
---
## 6. 负面提示词速查
diff --git a/tools/nano_banana_gen.py b/tools/nano_banana_gen.py
index e0db5ede..85a8061a 100644
--- a/tools/nano_banana_gen.py
+++ b/tools/nano_banana_gen.py
@@ -37,9 +37,9 @@ def save_binary_file(file_name: str, data: bytes):
print(f"File saved to: {file_name}")
-def generate(prompt: str, negative_prompt: str = None,
+def generate(prompt: str, negative_prompt: str = None,
aspect_ratio: str = "1:1", image_size: str = "4K",
- output_dir: str = None):
+ output_dir: str = None, filename: str = None):
"""
调用 Gemini API 生成图像
@@ -49,6 +49,7 @@ def generate(prompt: str, negative_prompt: str = None,
aspect_ratio: 图片宽高比 (默认 1:1)
image_size: 图片尺寸 (1K, 2K, 4K)
output_dir: 输出目录 (可选,默认为当前目录)
+ filename: 指定输出文件名 (不含扩展名,可选)
"""
# Load configuration
# Priority: Environment Variables > Config File
@@ -105,16 +106,11 @@ def generate(prompt: str, negative_prompt: str = None,
ratio_suffix = aspect_ratio.replace(":", "x")
model += f"-{ratio_suffix}"
- # Append aspect ratio to prompt for models that support prompt-based config
prompt_with_config = f"{prompt} --ar {aspect_ratio}"
# Structure the prompt to include negative prompt if provided
- # Note: While some APIs have a dedicated negative_prompt field, putting it in the text
- # is a robust fallback for this specific client wrapper if the field isn't exposed.
- # We will try to pass it clearly in the text.
final_prompt_text = prompt_with_config
if negative_prompt:
- # Common convention for text-to-image prompts
final_prompt_text += f"\n\nNegative prompt: {negative_prompt}"
print(f"Generating image with prompt: '{final_prompt_text}'")
@@ -137,11 +133,13 @@ def generate(prompt: str, negative_prompt: str = None,
image_config=types.ImageConfig(
aspect_ratio=aspect_ratio,
image_size=image_size,
- output_mime_type="image/png",
),
)
file_index = 0
+ image_saved = False # Track if we successfully saved an image
+ server_text_response = None # Capture any text response from server
+
try:
for chunk in client.models.generate_content_stream(
model=model,
@@ -158,13 +156,23 @@ def generate(prompt: str, negative_prompt: str = None,
part = chunk.candidates[0].content.parts[0]
if part.inline_data and part.inline_data.data:
# Use a descriptive filename based on prompt (sanitized) or default
- # We use the ORIGINAL prompt for naming, not the one with flags
- safe_prompt = "".join([c for c in prompt if c.isalnum() or c in (' ', '_')]).rstrip()
- safe_prompt = safe_prompt.replace(" ", "_").lower()[:30] # Increased length
- if not safe_prompt:
- safe_prompt = "generated_image"
+ if filename:
+ file_name = f"{filename}"
+ # If multiple chunks (unlikely for single image request but loop suggests stream),
+ # handle indexing only if strictly necessary or for safety?
+ # For this tool, we assume 1 image per request usually.
+ # But if valid multiple images arrive, we append index for subsequent ones.
+ if file_index > 0:
+ file_name = f"{filename}_{file_index}"
+ else:
+ # We use the ORIGINAL prompt for naming, not the one with flags
+ safe_prompt = "".join([c for c in prompt if c.isalnum() or c in (' ', '_')]).rstrip()
+ safe_prompt = safe_prompt.replace(" ", "_").lower()[:30] # Increased length
+ if not safe_prompt:
+ safe_prompt = "generated_image"
+
+ file_name = f"{safe_prompt}_{file_index}"
- file_name = f"{safe_prompt}_{file_index}"
file_index += 1
inline_data = part.inline_data
data_buffer = inline_data.data
@@ -182,8 +190,18 @@ def generate(prompt: str, negative_prompt: str = None,
else:
full_path = file_name_with_ext
save_binary_file(full_path, data_buffer)
- else:
- pass # Text content or other non-image content
+ image_saved = True # Mark that we saved an image
+ elif part.text:
+ # Capture text response (could be error message or additional info)
+ server_text_response = part.text
+ # Ignore empty chunks silently - they're just stream signals
+
+ # After stream ends, report status
+ if server_text_response:
+ print(f"Server Response: {server_text_response}")
+
+ if not image_saved:
+ print("Warning: No image was generated. The server may have refused the request.")
except Exception as e:
print(f"An error occurred: {e}")
@@ -214,6 +232,12 @@ if __name__ == "__main__":
help="Output directory for generated images. If not specified, saves to current directory."
)
+ parser.add_argument(
+ "--filename", "-f",
+ default=None,
+ help="Specific filename for the generated image (without extension). Overrides auto-naming."
+ )
+
args = parser.parse_args()
- generate(args.prompt, args.negative_prompt, args.aspect_ratio, args.image_size, args.output)
+ generate(args.prompt, args.negative_prompt, args.aspect_ratio, args.image_size, args.output, args.filename)