| name | image-generator |
| description | 调用大模型API生成图片的自动化工具。当用户需要生成AI图片、为内容创建配图、或需要自动化图片生成流程时使用此skill。支持从环境变量获取大模型配置,使用nano-banana-pro-prompts-recommend-skill优化提示词,支持多种图片格式和尺寸配置。 |
Image Generator
⚠️ 重要执行规范
1. Python 环境
必须在执行任何命令前,先激活 conda 环境:
conda activate qwen3-tts
2. 执行方式
禁止直接在 shell 中拼接 --prompt 参数执行脚本,因为 prompt 内容中可能含有单引号、双引号等特殊字符,会导致 bash 解析出现 quote> 错误。
必须使用 python3 -c 内联脚本方式,通过 subprocess.run 列表传参,完全绕过 shell 引号解析:
conda activate qwen3-tts && python3 -c "
import subprocess
import sys
prompt = '''在这里写提示词,可以包含任意单引号和特殊字符'''
result = subprocess.run(
[sys.executable, '/path/to/generate_image.py',
'--prompt', prompt,
'--size', '1K',
'--aspect-ratio', '16:9',
'--output', '/path/to/output.png',
'--format', 'png'],
capture_output=True, text=True
)
print(result.stdout)
print(result.stderr)
"
💡 原因:python3 -c 内联脚本中使用三引号 ''' 包裹 prompt,subprocess.run 以列表方式传参,参数内容原样传递,不经过 shell 解析,彻底避免引号冲突问题。
快速开始
环境配置
支持两种配置方式:
方式一:环境变量(推荐)
设置环境变量以配置大模型 API:
export LLM_BASE_URL="http://dev.fit-ai.woa.com/api/llmproxy"
export LLM_MODEL="gemini-3-pro-image"
export LLM_API_KEY="your-api-key"
方式二:JSON 配置文件
创建 generate_image.json 文件,包含大模型配置:
{
"LLM_BASE_URL": "http://dev.fit-ai.woa.com/api/llmproxy",
"LLM_MODEL": "gemini-3-pro-image",
"LLM_API_KEY": "your-api-key"
}
脚本会优先使用 JSON 配置文件,如果文件不存在则回退到环境变量。
基本使用
使用 JSON 配置文件(推荐)
生成图片(使用规范的执行方式):
conda activate qwen3-tts && python3 -c "
import subprocess
import sys
prompt = '''一只可爱的橘猫在花园里晒太阳'''
result = subprocess.run(
[sys.executable, '/path/to/generate_image.py',
'--prompt', prompt,
'--size', '1K',
'--aspect-ratio', '16:9',
'--output', './output.png',
'--format', 'png'],
capture_output=True, text=True
)
print(result.stdout)
print(result.stderr)
"
核心功能
图片生成脚本
scripts/generate_image.py 支持以下参数:
--prompt: 图片生成提示词(必填)
--size: 图片尺寸(1K、2K 等),默认"1K"
--aspect-ratio: 宽高比(1:1、16:9、9:16 等),默认"1:1"
--output: 输出文件路径,默认"./generated_image.png"
--format: 图片格式(png、jpg、jpeg),默认"png"
API 配置
支持两种配置方式,优先级:JSON 文件 > 环境变量
JSON 配置文件(推荐)
创建 scripts/generate_image.json 文件:
{
"LLM_BASE_URL": "http://dev.fit-ai.woa.com/api/llmproxy",
"LLM_MODEL": "gemini-3-pro-image",
"LLM_API_KEY": "your-api-key"
}
文件位置:scripts/generate_image.json(与 generate_image.py 同级目录)
配置字段:
- LLM_BASE_URL: 大模型 API 基础 URL(必填)
- LLM_MODEL: 大模型名称(必填)
- LLM_API_KEY: API 密钥(可选)
环境变量配置
设置环境变量:
export LLM_BASE_URL="http://dev.fit-ai.woa.com/api/llmproxy"
export LLM_MODEL="gemini-3-pro-image"
export LLM_API_KEY="your-api-key"
优先级:脚本优先使用 JSON 配置文件,如果文件不存在或配置不完整,则回退到环境变量。
提示词优化
自动使用 nano-banana-pro-prompts-recommend-skill 优化提示词,提高图片质量。
使用场景
内容配图生成
为博客文章、技术文档、社交媒体内容生成配图。
产品原型设计
快速生成 UI 界面、产品概念图、设计稿。
营销素材制作
生成活动海报、宣传图片、广告素材。
资源参考
示例脚本
scripts/example_generate_image.py 提供完整的示例代码,可直接运行测试图片生成功能。
JSON 配置文件使用指南
配置文件位置
将 generate_image.json 文件放置在 scripts/ 目录下,与 generate_image.py 脚本同级:
scripts/
├── generate_image.py
├── generate_image.json # 配置文件
├── example_generate_image.py
└── ...
配置示例
scripts/generate_image.json 文件示例:
{
"LLM_BASE_URL": "http://dev.fit-ai.woa.com/api/llmproxy",
"LLM_MODEL": "gemini-3-pro-image",
"LLM_API_KEY": "your-api-key"
}
最佳实践
- 安全存储:API 密钥等敏感信息建议使用环境变量,避免在配置文件中明文存储
- 版本控制:将配置文件添加到
.gitignore,避免敏感信息提交到代码仓库
- 环境区分:可为不同环境创建不同的配置文件,如
generate_image.dev.json、generate_image.prod.json
- 配置验证:脚本会自动验证配置文件格式和必填字段
故障排除
- 配置文件不存在:脚本自动回退到环境变量配置
- 配置字段缺失:脚本会提示缺失的必填字段并退出
- JSON 格式错误:脚本会显示解析错误并回退到环境变量
配置优先级
- ✅ JSON 配置文件(
scripts/generate_image.json)
- 🔄 环境变量(
LLM_BASE_URL、LLM_MODEL、LLM_API_KEY)
- ❌ 无配置(脚本报错退出)
Resources
This skill includes example resource directories that demonstrate how to organize different types of bundled resources:
scripts/
Executable code (Python/Bash/etc.) that can be run directly to perform specific operations.
Examples from other skills:
- PDF skill:
fill_fillable_fields.py, extract_form_field_info.py - utilities for PDF manipulation
- DOCX skill:
document.py, utilities.py - Python modules for document processing
Appropriate for: Python scripts, shell scripts, or any executable code that performs automation, data processing, or specific operations.
Note: Scripts may be executed without loading into context, but can still be read by Claude for patching or environment adjustments.
references/
Documentation and reference material intended to be loaded into context to inform Claude's process and thinking.
Examples from other skills:
- Product management:
communication.md, context_building.md - detailed workflow guides
- BigQuery: API reference documentation and query examples
- Finance: Schema documentation, company policies
Appropriate for: In-depth documentation, API references, database schemas, comprehensive guides, or any detailed information that Claude should reference while working.
assets/
Files not intended to be loaded into context, but rather used within the output Claude produces.
Examples from other skills:
- Brand styling: PowerPoint template files (.pptx), logo files
- Frontend builder: HTML/React boilerplate project directories
- Typography: Font files (.ttf, .woff2)
Appropriate for: Templates, boilerplate code, document templates, images, icons, fonts, or any files meant to be copied or used in the final output.
Any unneeded directories can be deleted. Not every skill requires all three types of resources.