hocgin/agent-skills/image-gen
Claude Code and agent skill by hocgin/agent-skills
- community
Checking that the SKILL.md file is still in the repository.
基于 APIMart GPT-Image-2 官方渠道的图像生成。支持文生图、图生图(多参考图融合)、局部重绘(mask)。异步任务模式, 需 APIMART_API_KEY 环境变量。当用户需要生成图片、编辑图片、局部重绘时使用此 skill。
Install
npx vskill@latest install hocgin/agent-skills/image-genSKILL.md
The same SKILL.md was published earlier as hocgin/agent-skills/image-gen.
image-gen
基于 APIMart GPT-Image-2 官方渠道 的图像生成 skill。支持文生图、图生图、局部重绘, 异步任务模式。
API 文档: https://docs.apimart.ai/cn/api-reference/images/gpt-image-2/official
前置条件
1. 检查 API Key
2. 若无 API Key
引导用户:
需要先配置 APIMart API Key:1. 访问 APIMart 控制台 注册并获取 API Key2. 在终端中设置环境变量:```bashexport APIMART_API_KEY="your_api_key_here"```建议将上述命令加入~/.zshrc或~/.bashrc持久化。
API 端点
- 提交任务:
POST https://api.apimart.ai/v1/images/generations - 查询任务:
GET https://api.apimart.ai/v1/tasks/{task_id} - 批量查询:
POST https://api.apimart.ai/v1/tasks/batch
请求参数
| 参数 | 类型 | 默认值 | 必填 | 说明 | |
|---|---|---|---|---|---|
model | string | gpt-image-2-official | 是 | 固定值 | |
prompt | string | - | 是 | 图像描述, 支持中英文, 建议英文 | |
size | string | 1:1 | 否 | 画面比例, 见下方映射表 | |
resolution | string | 1k | 否 | 分辨率档位: 1k/2k/4k | |
quality | string | auto | 否 | auto/low/medium/high | |
background | string | auto | 否 | auto/opaque/transparent(不支持, 会降级为 auto) | |
moderation | string | auto | 否 | auto/low | |
output_format | string | png | 否 | png/jpeg/webp | |
output_compression | integer | - | 否 | 压缩强度 0-100, 仅 jpeg/webp 有效 | |
n | integer | 1 | 否 | 生成张数, 1-4 | |
image_urls | array | - | 否 | 参考图 URL, 最多 16 张 | |
mask_url | string | - | 否 | 遮罩图 URL, 需搭配 image_urls |
支持的比例
auto/1:1/3:2/2:3/4:3/3:4/5:4/4:5/16:9/9:16/2:1/1:2/3:1/1:3/21:9/9:21
也支持直接传像素尺寸, 如 3840x2160。
尺寸 x 分辨率映射表
| size | 1k | 2k | 4k | |
|---|---|---|---|---|
| 1:1 | 1024x1024 | 2048x2048 | 2880x2880 | |
| 3:2 | 1536x1024 | 2048x1360 | 3520x2336 | |
| 2:3 | 1024x1536 | 1360x2048 | 2336x3520 | |
| 4:3 | 1024x768 | 2048x1536 | 3312x2480 | |
| 3:4 | 768x1024 | 1536x2048 | 2480x3312 | |
| 5:4 | 1280x1024 | 2560x2048 | 3216x2576 | |
| 4:5 | 1024x1280 | 2048x2560 | 2576x3216 | |
| 16:9 | 1536x864 | 2048x1152 | 3840x2160 | |
| 9:16 | 864x1536 | 1152x2048 | 2160x3840 | |
| 2:1 | 2048x1024 | 2688x1344 | 3840x1920 | |
| 1:2 | 1024x2048 | 1344x2688 | 1920x3840 | |
| 3:1 | 1536x512 | 3072x1024 | 3840x1280 | |
| 1:3 | 512x1536 | 1024x3072 | 1280x3840 | |
| 21:9 | 2016x864 | 2688x1152 | 3840x1648 | |
| 9:21 | 864x2016 | 1152x2688 | 1648x3840 |
工作流程
Step 1: 提交任务
返回:
Step 2: 轮询任务状态
等待 10-20 秒后开始查询, 间隔 3-5 秒:
任务状态流转: submitted -> in_progress -> completed / failed
Step 3: 获取结果
成功响应:
取图地址: data.result.images[0].url[0]
Step 4: 下载图片
完整脚本示例(提交 + 轮询 + 下载)
使用场景
文生图(最简)
2K 高清海报
图生图(多参考图融合)
局部重绘(mask)
遮罩图需有 Alpha 通道, 尺寸需与首张参考图一致。
批量生成(n > 1)
4K 壁纸
Prompt 编写原则
- 用英文描述。模型支持中文, 但英文效果更稳定。
- 具体胜过抽象。"Space-black MacBook Pro 16-inch M3 on a walnut desk" > "a laptop on desk"。
- 描述构图而非意图。"Medium shot, subject centered, banker lamp backlighting" > "dramatic portrait"。
- 明确排除项。"No emojis, no gradients, no stock photo aesthetic"。
- 图片中的文字用引号。
reads "Hello World"-- 准确率约 99%。 - cinematographic reference(如果适合风格)。"In the visual style of Blade Runner 2049 desert scenes"。
轮询策略
| 条件 | 建议值 | |
|---|---|---|
| 首次查询延迟 | 10-20 秒 | |
| 查询间隔 | 3-5 秒 | |
| 超时时间 | >= 180 秒(high + 2k/4k 可达 130s) |
Troubleshooting
`401` 未授权 API Key 无效或过期。检查 APIMART_API_KEY 环境变量, 到 APIMart 控制台 重新获取。
`402` 余额不足 账户余额不够, 到 APIMart 控制台充值。
`429` 限流 请求过于频繁, 降低轮询频率或稍后重试。
`400` 参数错误 检查请求参数: model 是否为 gpt-image-2-official, size 是否在支持列表中, n 是否为 1-4。
任务 `failed` 可能是审核拦截(prompt 违规)或服务端错误。尝试修改 prompt 降低敏感度后重试。
图片链接过期 data.result.images[0].expires_at 是过期时间戳, 到期后链接失效。需及时下载。
`high` + `4k` 耗时过长 正常现象, 耗时可达 130 秒以上。客户端超时建议 >= 180 秒。
耗时与质量参考
| 分辨率 | quality | 预计耗时 | 适用场景 | |
|---|---|---|---|---|
| 1k | low | ~10-20s | 草稿/预览 | |
| 1k | medium | ~20-40s | 日常使用 | |
| 2k | medium | ~30-60s | 海报/高清 | |
| 2k | high | ~60-100s | 高质量输出 | |
| 4k | high | ~100-130s | 壁纸/印刷 |
参考链接
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/image-gen/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hocgin/agent-skills/image-gen)