关于 baoyu-image-gen
baoyu-image-gen 是通过 AI SDK 调用 OpenAI 和 Google 图像模型生成图像的技能,适合需要命令行图像生成与编辑的工作流。它支持参考图、尺寸和画质选项,并可自动选择提供方。
主要功能
- 01调用 OpenAI 和 Google 图像模型
- 02提示词文件输入
- 03设置宽高比、尺寸与画质
- 04使用参考图编辑或组合风格
- 05批量指定生成数量
- 06纯文本或 JSON 输出
适用场景
- 01生成封面和插图
- 02制作社交媒体方图
- 03基于原图调整背景或风格
- 04从提示词文件生成场景图
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ smallnest/ langgraphgo --skill baoyu-image-gen安装后在 Claude Code 中输入/baoyu-image-gen确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
package-lock.jsonpackage.jsonscripts/main.ts详细介绍
图像生成(AI SDK)
通过基于官方 API 的方式生成图像。支持 OpenAI(DALL-E、GPT Image)和 Google(Imagen、Gemini 多模态)。
脚本目录
重要:所有脚本都位于此技能的 scripts/ 子目录中。
Agent 执行说明:
- 将此 SKILL.md 文件所在目录路径确定为
SKILL_DIR - 脚本路径 =
${SKILL_DIR}/scripts/<script-name>.ts - 将本文档中的所有
${SKILL_DIR}替换为实际路径
脚本参考:
| 脚本 | 用途 |
|---|---|
scripts/main.ts | 图像生成 CLI 入口点 |
快速开始
# Basic generation (auto-detect provider)
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A cat" --image cat.png
# With aspect ratio
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A landscape" --image landscape.png --ar 16:9
# High quality (2k)
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A cat" --image cat.png --quality 2k
# Specific provider
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A cat" --image cat.png --provider openai
# From prompt files
npx -y bun ${SKILL_DIR}/scripts/main.ts --promptfiles system.md content.md --image out.png
# With reference images (Google multimodal only)
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "Make blue" --image out.png --ref source.png
命令
基本图像生成
# Generate with prompt
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A sunset over mountains" --image sunset.png
# Shorthand
npx -y bun ${SKILL_DIR}/scripts/main.ts -p "A cute robot" --image robot.png
宽高比
# Common ratios: 1:1, 16:9, 9:16, 4:3, 3:4, 2.35:1
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A portrait" --image portrait.png --ar 3:4
# Or specify exact size
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "Banner" --image banner.png --size 1792x1024
参考图像(Google 多模态)
# Image editing with reference
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "Make it blue" --image blue.png --ref original.png
# Multiple references
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "Combine these styles" --image out.png --ref a.png b.png
质量预设
# Normal quality (default)
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A cat" --image cat.png --quality normal
# High quality (2k resolution)
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A cat" --image cat.png --quality 2k
输出格式
# Plain output (prints saved path)
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A cat" --image cat.png
# JSON output
npx -y bun ${SKILL_DIR}/scripts/main.ts --prompt "A cat" --image cat.png --json
选项
| 选项 | 描述 |
|---|---|
--prompt <text>、-p | 提示词文本 |
--promptfiles <files...> | 从文件读取提示词(拼接) |
--image <path> | 输出图像路径(必填) |
--provider google|openai | 强制指定提供方(默认:google) |
--model <id>、-m | 模型 ID |
--ar <ratio> | 宽高比(例如:16:9、1:1、4:3) |
--size <WxH> | 尺寸(例如:1024x1024) |
--quality normal|2k | 质量预设(默认:normal) |
--ref <files...> | 参考图像(仅限 Google 多模态) |
--n <count> | 图像数量 |
--json | JSON 输出 |
--help、-h | 显示帮助 |
环境变量
| 变量 | 描述 | 默认值 |
|---|---|---|
OPENAI_API_KEY | OpenAI API 密钥 | - |
GOOGLE_API_KEY | Google API 密钥 | - |
OPENAI_IMAGE_MODEL | OpenAI 模型 | gpt-image-1.5 |
GOOGLE_IMAGE_MODEL | Google 模型 | gemini-3-pro-image-preview |
OPENAI_BASE_URL | 自定义 OpenAI 端点 | - |
GOOGLE_BASE_URL | 自定义 Google 端点 | - |
加载优先级:CLI 参数 > process.env > <cwd>/.baoyu-skills/.env > ~/.baoyu-skills/.env
提供方与模型策略
自动选择
- 如果指定了
--provider→ 使用该提供方 - 如果只有一个 API 密钥可用 → 使用对应的提供方
- 如果两个密钥都可用 → 默认使用 Google(多模态大模型用途更广)
按模型类型选择 API
| 模型类别 | API 函数 | 示例模型 |
|---|---|---|
| Google 多模态 | generateText | gemini-2.0-flash-exp-image-generation |
| Google Imagen | experimental_generateImage | imagen-3.0-generate-002 |
| OpenAI | experimental_generateImage | gpt-image-1、dall-e-3 |
可用模型
Google:
gemini-3-pro-image-preview- 默认,多模态生成gemini-2.0-flash-exp-image-generation- Gemini 2.0 Flashimagen-3.0-generate-002- Imagen 3
OpenAI:
gpt-image-1.5- 默认,GPT Image 1.5gpt-image-1- GPT Image 1dall-e-3- DALL-E 3
质量预设
| 预设 | OpenAI | 使用场景 | |
|---|---|---|---|
normal | 1024x1024 | 默认 | 封面、插图 |
2k | 2048x2048 | 提示词中写入“2048px” | 信息图、幻灯片 |
宽高比处理
- 多模态大模型:嵌入提示词中(例如:
"... aspect ratio 16:9") - 纯图像模型:使用
aspectRatio或size参数 - 常见比例:1:1、16:9、9:16、4:3、3:4、2.35:1
示例
生成封面图像
npx -y bun ${SKILL_DIR}/scripts/main.ts \
--prompt "A minimalist tech illustration with blue gradients" \
--image cover.png --ar 2.35:1 --quality 2k
生成社交媒体帖子
npx -y bun ${SKILL_DIR}/scripts/main.ts \
--prompt "Instagram post about coffee" \
--image post.png --ar 1:1
使用参考图像编辑图像
npx -y bun ${SKILL_DIR}/scripts/main.ts \
--prompt "Change the background to sunset" \
--image edited.png --ref original.png --provider google
根据提示词文件批量生成
# Create prompt file with detailed instructions
npx -y bun ${SKILL_DIR}/scripts/main.ts \
--promptfiles style-guide.md scene-description.md \
--image scene.png
错误处理
- 缺少 API 密钥:提供清晰的错误信息和设置说明
- 生成失败:自动重试一次,然后报错
- 无效宽高比:发出警告,并使用默认值继续
- 纯图像模型搭配参考图像:发出警告,并忽略参考图像
扩展支持
通过 EXTEND.md 自定义配置。
检查路径(优先级顺序):
.baoyu-skills/baoyu-image-gen/EXTEND.md(项目)~/.baoyu-skills/baoyu-image-gen/EXTEND.md(用户)
如果找到,则在工作流开始前加载。扩展内容会覆盖默认设置。
评论
支持 Markdown