关于 image-generation
image-generation 是通过结构化提示词和 Python 脚本生成图像的技能,面向需要创建角色、场景或产品视觉内容的用户。它支持参考图,并可根据环境变量选择图像生成服务提供方。
主要功能
- 01创建结构化 JSON 提示词
- 02支持多张参考图
- 03通过 Python 脚本生成图像
- 04支持角色、场景和产品图
- 05根据环境变量选择提供方
适用场景
- 01依据文字描述生成角色设计
- 02用参考图引导场景构图
- 03制作产品可视化图像
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ bytedance/ deer-flow --skill image-generation安装后在 Claude Code 中输入/image-generation确认已加载。
附带文件scripts/generate.pytemplates/doraemon.md
详细介绍
图像生成技能
概述
此技能使用结构化提示词和 Python 脚本生成高质量图像。工作流包括创建 JSON 格式的提示词,以及使用可选的参考图像执行图像生成。
核心功能
- 创建用于 AIGC 图像生成的结构化 JSON 提示词
- 支持多张参考图像,为风格和构图提供指导
- 通过自动执行 Python 脚本生成图像
- 处理各种图像生成场景(角色设计、场景、产品等)
工作流
步骤 1:了解需求
用户请求生成图像时,请确定:
- 主体/内容:图像中应包含什么
- 风格偏好:艺术风格、氛围、色彩搭配
- 技术规格:宽高比、构图、光照
- 参考图像:是否有用于指导生成的图像
- 无需检查
/mnt/user-data下的文件夹
步骤 2:创建结构化提示词
在 /mnt/user-data/workspace/ 中创建一个结构化 JSON 文件,命名格式为:{descriptive-name}.json
步骤 3:执行生成
调用 Python 脚本:
python /mnt/skills/public/image-generation/scripts/generate.py \
--prompt-file /mnt/user-data/workspace/prompt-file.json \
--reference-images /path/to/ref1.jpg /path/to/ref2.png \
--output-file /mnt/user-data/outputs/generated-image.jpg
--aspect-ratio 16:9
参数:
--prompt-file:JSON 提示词文件的绝对路径(必需)--reference-images:参考图像的绝对路径(可选,以空格分隔)--output-file:输出图像文件的绝对路径(必需)--aspect-ratio:生成图像的宽高比(可选,默认值:16:9)
[!NOTE] 请勿读取 Python 文件,只需使用参数调用它。
角色生成示例
用户请求:“创建一位 1990 年代的东京街头风格女性角色”
创建提示词文件:/mnt/user-data/workspace/asian-woman.json
{
"characters": [{
"gender": "female",
"age": "mid-20s",
"ethnicity": "Japanese",
"body_type": "slender, elegant",
"facial_features": "delicate features, expressive eyes, subtle makeup with emphasis on lips, long dark hair partially wet from rain",
"clothing": "stylish trench coat, designer handbag, high heels, contemporary Tokyo street fashion",
"accessories": "minimal jewelry, statement earrings, leather handbag",
"era": "1990s"
}],
"negative_prompt": "blurry face, deformed, low quality, overly sharp digital look, oversaturated colors, artificial lighting, studio setting, posed, selfie angle",
"style": "Leica M11 street photography aesthetic, film-like rendering, natural color palette with slight warmth, bokeh background blur, analog photography feel",
"composition": "medium shot, rule of thirds, subject slightly off-center, environmental context of Tokyo street visible, shallow depth of field isolating subject",
"lighting": "neon lights from signs and storefronts, wet pavement reflections, soft ambient city glow, natural street lighting, rim lighting from background neons",
"color_palette": "muted naturalistic tones, warm skin tones, cool blue and magenta neon accents, desaturated compared to digital photography, film grain texture"
}
执行生成:
python /mnt/skills/public/image-generation/scripts/generate.py \
--prompt-file /mnt/user-data/workspace/cyberpunk-hacker.json \
--output-file /mnt/user-data/outputs/cyberpunk-hacker-01.jpg \
--aspect-ratio 2:3
使用参考图像:
{
"characters": [{
"gender": "based on [Image 1]",
"age": "based on [Image 1]",
"ethnicity": "human from [Image 1] adapted to Star Wars universe",
"body_type": "based on [Image 1]",
"facial_features": "matching [Image 1] with slight weathered look from space travel",
"clothing": "Star Wars style outfit - worn leather jacket with utility vest, cargo pants with tactical pouches, scuffed boots, belt with holster",
"accessories": "blaster pistol on hip, comlink device on wrist, goggles pushed up on forehead, satchel with supplies, personal vehicle based on [Image 2]",
"era": "Star Wars universe, post-Empire era"
}],
"prompt": "Character inspired by [Image 1] standing next to a vehicle inspired by [Image 2] on a bustling alien planet street in Star Wars universe aesthetic. Character wearing worn leather jacket with utility vest, cargo pants with tactical pouches, scuffed boots, belt with blaster holster. The vehicle adapted to Star Wars aesthetic with weathered metal panels, repulsor engines, desert dust covering, parked on the street. Exotic alien marketplace street with multi-level architecture, weathered metal structures, hanging market stalls with colorful awnings, alien species walking by as background characters. Twin suns casting warm golden light, atmospheric dust particles in air, moisture vaporators visible in distance. Gritty lived-in Star Wars aesthetic, practical effects look, film grain texture, cinematic composition.",
"negative_prompt": "clean futuristic look, sterile environment, overly CGI appearance, fantasy medieval elements, Earth architecture, modern city",
"style": "Star Wars original trilogy aesthetic, lived-in universe, practical effects inspired, cinematic film look, slightly desaturated with warm tones",
"composition": "medium wide shot, character in foreground with alien street extending into background, environmental storytelling, rule of thirds",
"lighting": "warm golden hour lighting from twin suns, rim lighting on character, atmospheric haze, practical light sources from market stalls",
"color_palette": "warm sandy tones, ochre and sienna, dusty blues, weathered metals, muted earth colors with pops of alien market colors",
"technical": {
"aspect_ratio": "9:16",
"quality": "high",
"detail_level": "highly detailed with film-like texture"
}
}
python /mnt/skills/public/image-generation/scripts/generate.py \
--prompt-file /mnt/user-data/workspace/star-wars-scene.json \
--reference-images /mnt/user-data/uploads/character-ref.jpg /mnt/user-data/uploads/vehicle-ref.jpg \
--output-file /mnt/user-data/outputs/star-wars-scene-01.jpg \
--aspect-ratio 16:9
常见场景
针对不同场景使用不同的 JSON 架构。
角色设计:
- 身体特征(性别、年龄、族裔、体型)
- 面部特征和表情
- 服装和配饰
- 历史时期或背景设定
- 姿势和情境
场景生成:
- 环境描述
- 时间、天气
- 氛围和情绪
- 焦点和构图
产品可视化:
- 产品细节和材质
- 灯光布置
- 背景和情境
- 展示角度
专用模板
仅在用户请求与以下模板匹配时阅读该模板文件。
输出处理
生成后:
- 图像通常保存在
/mnt/user-data/outputs/ - 使用 present_files 工具与用户分享生成的图像
- 简要描述生成结果
- 如果需要调整,提出可以继续迭代
提示:使用参考图像增强生成效果
对于视觉准确性至关重要的场景,请先使用 image_search 工具查找参考图像,再进行生成。
建议使用 image_search 工具的场景:
- 角色/肖像生成:搜索相似的姿势、表情或风格,为面部特征和身体比例提供指导
- 特定物体或产品:查找真实物体的参考图像,确保呈现准确
- 建筑或环境场景:搜索地点参考图像,呈现真实细节
- 时尚和服装:查找风格参考图像,确保服装细节和造型准确
示例工作流:
- 调用
image_search工具查找合适的参考图像:image_search(query="Japanese woman street photography 1990s", size="Large") - 将返回的图像 URL 下载到本地文件
- 在生成脚本中将下载的图像用作
--reference-images参数
这种方法可为模型提供具体的视觉指导,而非仅依赖文字描述,从而显著提升生成质量。
提供方(Gemini / MiniMax / OpenAI 兼容)
此技能会根据环境变量自动选择提供方(无需更改命令行):
- 设置了
GEMINI_API_KEY→ 使用 Gemini(默认,保持不变)。 - 否则,若设置了
MINIMAX_API_KEY→ 使用 MiniMax(/v1/image_generation,模型为image-01)。 - 否则,若设置了
IMAGE_GENERATION_API_KEY→ 使用 OpenAI 兼容的图像 API。 - 使用
IMAGE_GENERATION_PROVIDER=gemini|minimax|openai强制指定提供方。 也接受openai-compatible作为openai的别名。
OpenAI 兼容设置:
IMAGE_GENERATION_API_KEY(必需)IMAGE_GENERATION_BASE_URL(默认https://api.openai.com/v1)IMAGE_GENERATION_MODEL(默认gpt-image-2.5-flare)IMAGE_GENERATION_SIZE(可选的固定尺寸覆盖值)
文生图调用使用 POST {base_url}/images/generations。参考图调用使用 multipart
POST {base_url}/images/edits;中继服务可能支持生成,但不支持编辑。响应可能包含
base64 图像数据、数据 URL 或可下载的 URL。除非设置了
IMAGE_GENERATION_SIZE,否则宽高比会映射为 1024x1024、1536x1024 或 1024x1536。
输出扩展名决定 API 的 output_format:
.jpg/.jpeg 使用 jpeg,.webp 使用 webp,其他扩展名均使用 png。
如果配置的是 dall-e-2 或 dall-e-3,则请求会使用该模型支持的尺寸和
response_format=b64_json;DALL-E 输出文件必须使用 .png 扩展名。此技能不支持使用 DALL-E 模型编辑参考图;编辑时请使用默认的 GPT Image 模型。
MiniMax 可选覆盖值:MINIMAX_API_HOST(默认 https://api.minimaxi.com)、
MINIMAX_IMAGE_MODEL(默认 image-01)。参考图会作为 MiniMax 的
subject_reference 角色图像发送。两个提供方使用相同的 CLI 和
--prompt-file / --reference-images / --output-file / --aspect-ratio 参数。
MiniMax 提示词处理(提供方内部)。 提示词编写与提供方无关——无论当前使用哪个提供方,都编写相同的结构化 JSON。MiniMax image-01 接收单个文本字符串,因此 MiniMax 路径本身只会发送 JSON 的 prompt 字段(其他字段,如 style / composition / negative_prompt,适用于 Gemini 路径),并启用 prompt_optimizer,以便 MiniMax 在服务端扩展提示词。MiniMax 对该提示词的长度上限为 1500 个字符;如果 prompt 字段超出此长度,脚本会返回错误,而不会调用 API。Gemini 路径会接收完整的结构化 JSON。
注意事项
- 无论用户使用何种语言,提示词始终使用英文
- JSON 格式可确保提示词结构化且可解析
- 参考图可显著提升生成质量
- 反复优化是获得最佳结果的正常过程
- 生成角色时,请提供详细的角色对象以及汇总后的提示词字段