generating-images
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGenerating Images (OpenAI gpt-image-2)
生成图像(OpenAI gpt-image-2)
Use this skill any time the user asks to generate or edit an image. It wraps
OpenAI's model via a Python script, supports both text-only
prompts and one-or-more reference images, and writes the resulting PNG/JPEG/WebP
to disk.
gpt-image-2每当用户要求生成或编辑图像时,均可使用此技能。它通过Python脚本封装了OpenAI的模型,支持纯文本提示词和一张或多张参考图像,并将生成的PNG/JPEG/WebP格式图像写入磁盘。
gpt-image-2Hard rules (do not violate)
硬性规则(不得违反)
- Always use . Never fall back to
gpt-image-2,gpt-image-1, or any other model. The script has nodall-e-3flag for this reason.--model - Fail fast on any error. Do not retry, do not swap models, do not patch around missing credentials, do not silently degrade quality. If the script exits non-zero, surface the error to the user verbatim and stop.
- Do not "fix" a missing by reading from
OPENAI_API_KEYfiles, 1Password, etc. unless the user explicitly tells you to. If the env var is missing, ask the user how they want to provide it (or to.envit) and then stop.export
- 始终使用。绝不降级使用
gpt-image-2、gpt-image-1或其他任何模型。为此,脚本未设置dall-e-3参数。--model - 遇到错误立即终止。不要重试,不要切换模型,不要绕过缺失的凭证问题,不要悄悄降低质量。如果脚本非零退出,直接将错误原封不动告知用户并停止操作。
- 不要主动修复缺失的,除非用户明确指示,否则不要从.env文件、1Password等位置读取密钥。如果环境变量缺失,请询问用户提供方式(或让用户执行
OPENAI_API_KEY命令),然后停止操作。export
When to use
使用场景
- User asks for a generated image: icon, logo, illustration, mockup, OG image, blog hero, marketing asset, concept art, diagram-style image, etc.
- User provides one or more images and asks to edit, restyle, combine, or use them as references.
- User asks to remove/replace part of an image (use ).
--mask
Do not use this skill for:
- Charts/plots/data viz (generate via code instead).
- Sourcing existing photos (use a stock photo skill if available).
- Screenshots of the user's app (use a screenshot skill if available).
- 用户要求生成图像:图标、Logo、插画、模型图、OG图像、博客首图、营销素材、概念艺术、图表风格图像等。
- 用户提供一张或多张图像,要求编辑、重新设计风格、组合或作为参考使用。
- 用户要求移除/替换图像的部分内容(使用参数)。
--mask
请勿将此技能用于:
- 图表/绘图/数据可视化(应通过代码生成)。
- 获取现有照片(如有可用的图库照片技能,请使用该技能)。
- 截取用户应用的屏幕截图(如有可用的截图技能,请使用该技能)。
Prerequisites
前置条件
1. OpenAI API key
1. OpenAI API密钥
You need an exported in your environment. Get one at
platform.openai.com/api-keys.
OPENAI_API_KEYThe skill ships with a next to this . Copy it and
fill in your key:
.env.exampleSKILL.mdbash
cp .env.example .env您需要在环境变量中导出。可前往platform.openai.com/api-keys获取。
OPENAI_API_KEY本技能在旁提供了文件。复制该文件并填入您的密钥:
SKILL.md.env.examplebash
cp .env.example .envthen edit .env and put your real key in
编辑.env文件并填入真实密钥
Then export it before running the script:
```bash
set -a && source .env && set +aOr just export it directly in your shell:
bash
export OPENAI_API_KEY="sk-..."If is not set, the script exits with code 2 immediately.
Do not try to read it from anywhere else without the user's explicit
permission.
OPENAI_API_KEY
运行脚本前导出密钥:
```bash
set -a && source .env && set +a或者直接在shell中导出:
bash
export OPENAI_API_KEY="sk-..."如果未设置,脚本会立即以代码2退出。未经用户明确许可,请勿尝试从其他位置读取密钥。
OPENAI_API_KEY2. Org verification
2. 组织验证
Your OpenAI org must be verified for at
platform.openai.com/settings/organization/general.
If you see a 403 mentioning "organization must be verified", surface it and
stop — do not switch models.
gpt-image-2您的OpenAI组织必须在platform.openai.com/settings/organization/general完成的验证。如果收到403错误提示“organization must be verified”,请告知用户并停止操作——不要切换模型。
gpt-image-23. Python dependency
3. Python依赖
bash
pip install --upgrade openaibash
pip install --upgrade openaiScript location
脚本位置
The Python script lives next to this at .
When this skill is installed at , the
script will be at .
SKILL.mdscripts/generate_image.py~/.cursor/skills/generating-images/~/.cursor/skills/generating-images/scripts/generate_image.pyIt prints the absolute path(s) of the written image(s) to stdout. Errors go
to stderr with a non-zero exit code, and the script exits immediately on the
first error.
Python脚本位于旁的。当本技能安装在时,脚本路径为。
SKILL.mdscripts/generate_image.py~/.cursor/skills/generating-images/~/.cursor/skills/generating-images/scripts/generate_image.py脚本会将生成图像的绝对路径打印到标准输出。错误信息会输出到标准错误流并伴随非零退出码,且脚本会在首次出错时立即退出。
How to invoke
调用方式
Always run via the Shell tool. Pick a sensible output path inside the user's
current workspace (e.g. for web projects, or
otherwise).
./public/generated/<slug>.png./<slug>.png始终通过Shell工具运行脚本。在用户当前工作区中选择合理的输出路径(例如,Web项目使用,其他项目使用)。
./public/generated/<slug>.png./<slug>.png1. Text-to-image
1. 文本转图像
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--prompt "Minimal flat-vector app icon for a note-taking app, indigo gradient, rounded square, soft shadow" \
--size 1024x1024 \
--quality high \
--out ./icon.pngbash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--prompt "极简扁平化矢量笔记应用图标,靛蓝渐变,圆角方形,柔和阴影" \
--size 1024x1024 \
--quality high \
--out ./icon.png2. Image-to-image (one reference)
2. 图像转图像(单张参考图)
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--prompt "Restyle this photo as a watercolor painting with warm tones" \
--image ./photo.jpg \
--out ./photo-watercolor.pngbash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--prompt "将这张照片重新设计为暖色调水彩画风格" \
--image ./photo.jpg \
--out ./photo-watercolor.png3. Multiple reference images
3. 多张参考图像
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--prompt "Photorealistic flat-lay product shot combining all of these items on a white background" \
--image ./a.png --image ./b.png --image ./c.png \
--out ./flatlay.pngbash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--prompt "将所有物品组合在白色背景上的写实平铺产品照片" \
--image ./a.png --image ./b.png --image ./c.png \
--out ./flatlay.png4. Masked edit (inpainting)
4. 蒙版编辑(图像修复)
The mask must be the same size and format as the first input image, with an
alpha channel marking the editable region.
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--prompt "Replace the sky with a vivid sunset" \
--image ./scene.png --mask ./sky-mask.png \
--out ./scene-sunset.png蒙版必须与第一张输入图像尺寸和格式相同,且带有标记可编辑区域的Alpha通道。
bash
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--prompt "将天空替换为绚烂的日落" \
--image ./scene.png --mask ./sky-mask.png \
--out ./scene-sunset.png5. Batch / parallel mode (many distinct images at once)
5. 批量/并行模式(一次性生成多张不同图像)
When you need to generate multiple different images in one go (e.g. a set
of blog heroes, several icon variations with different prompts, OG images for
many pages), use instead of running the script N times. It runs all
jobs in parallel from a single Python process — much faster than serial calls
and avoids repeated SDK startup cost.
--batchWrite a JSON file describing every job, then call the script once:
bash
cat > /tmp/img-jobs.json <<'EOF'
[
{
"prompt": "Minimal flat-vector app icon for a note-taking app, indigo gradient, rounded square",
"out": "./public/icons/notes.png",
"size": "1024x1024",
"quality": "high"
},
{
"prompt": "Photoreal blog hero: a cozy library with warm afternoon light, 5:3 ratio",
"out": "./public/static/blog/library.png",
"size": "1600x960",
"quality": "medium"
},
{
"prompt": "Restyle this product photo as a watercolor painting with warm tones",
"image": ["./public/products/mug.jpg"],
"out": "./public/products/mug-watercolor.png"
}
]
EOF
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--batch /tmp/img-jobs.json --concurrency 5Each job object accepts the same fields as the CLI flags: (required),
, , , , , (string or array of strings),
. Defaults match the single-shot CLI.
promptoutsizequalityformatnimagemaskBehavior:
- All jobs run concurrently up to (default 4). A reasonable range is 3–8; OpenAI rate-limits per org so don't go too wild.
--concurrency - Each successfully written image's absolute path is printed to stdout as soon as that job finishes, one per line.
- If any job fails, its error is printed to stderr () and the script exits with code 1 after the remaining jobs finish. Other jobs are not cancelled — partial output is fine and you can retry only the failed ones.
ERROR: job <i> failed: ... - is mutually exclusive with
--batch/--prompt/--image.--mask
When to prefer over parallel Shell calls: any time you're
generating ≥2 distinct images in the same turn. Don't fire multiple parallel
Shell invocations of this script — use one batch call instead.
--batchDon't confuse with . produces multiple variations of the same
prompt in a single API call (cheaper, but all the same idea). runs
different prompts in parallel. They can be combined: a batch job can set
to get 4 variations of that one prompt.
--n--n--batch"n": 4当您需要一次性生成多张不同图像时(例如,一组博客首图、多个不同提示词的图标变体、多个页面的OG图像),请使用参数,而非重复运行脚本N次。它会在单个Python进程中并行运行所有任务——比串行调用快得多,且避免重复的SDK启动开销。
--batch编写描述所有任务的JSON文件,然后调用一次脚本:
bash
cat > /tmp/img-jobs.json <<'EOF'
[
{
"prompt": "极简扁平化矢量笔记应用图标,靛蓝渐变,圆角方形",
"out": "./public/icons/notes.png",
"size": "1024x1024",
"quality": "high"
},
{
"prompt": "写实风格博客首图:温暖午后阳光下的舒适图书馆,5:3比例",
"out": "./public/static/blog/library.png",
"size": "1600x960",
"quality": "medium"
},
{
"prompt": "将这张产品照片重新设计为暖色调水彩画风格",
"image": ["./public/products/mug.jpg"],
"out": "./public/products/mug-watercolor.png"
}
]
EOF
python3 ~/.cursor/skills/generating-images/scripts/generate_image.py \
--batch /tmp/img-jobs.json --concurrency 5每个任务对象接受与CLI参数相同的字段:(必填)、、、、、、(字符串或字符串数组)、。默认值与单次调用CLI的设置一致。
promptoutsizequalityformatnimagemask行为说明:
- 所有任务会并行运行,最大并发数由设置(默认4)。合理范围为3–8;OpenAI会按组织进行速率限制,请勿设置过高。
--concurrency - 每个成功写入的图像绝对路径会在任务完成后立即打印到标准输出,每行一个路径。
- 如果任何任务失败,错误信息会输出到标准错误流(),脚本会在剩余任务完成后以代码1退出。其他任务不会被取消——允许部分输出,您可以仅重试失败的任务。
ERROR: job <i> failed: ... - 与
--batch/--prompt/--image互斥。--mask
何时优先使用而非并行Shell调用: 当您需要在同一轮操作中生成≥2张不同图像时。请勿触发多个并行的脚本Shell调用——请改用一次批量调用。
--batch不要与混淆。 会在单次API调用中生成同一提示词的多个变体(成本更低,但都是相同主题)。会并行运行不同的提示词。两者可以结合使用:批量任务中设置可生成该提示词的4个变体。
--n--n--batch"n": 4Flags reference
参数参考
| Flag | Default | Notes |
|---|---|---|
| required* | Required unless |
| none | Pass multiple times for multiple references. Triggers |
| none | Optional inpainting mask (PNG with alpha). |
| | Output path; index suffix added when |
| | |
| | |
| | |
| | Variations of the SAME prompt in one call. |
| none | Path to JSON array of job objects; runs them in parallel. |
| | Max parallel workers in |
There is intentionally no flag. The model is hardcoded to
.
--modelgpt-image-2| 参数 | 默认值 | 说明 |
|---|---|---|
| 必填* | 除非使用 |
| 无 | 可多次传递以使用多张参考图。会触发 |
| 无 | 可选的图像修复蒙版(带Alpha通道的PNG)。 |
| | 输出路径;当 |
| | 可选值包括 |
| | 可选值: |
| | 可选值: |
| | 同一提示词的变体数量,单次调用生成。 |
| 无 | JSON格式任务数组的路径;并行运行这些任务。 |
| | |
脚本故意未设置参数,模型已硬编码为。
--modelgpt-image-2Sizing guidance
尺寸指南
- App icons / square thumbnails →
1024x1024 - Landing-page heroes / OG images →
1536x1024 - Blog hero (5:3) → (both edges multiples of 16, ratio = 5:3)
1600x960 - Mobile / portrait illustrations →
1024x1536 - Marketing posters / 4K assets →
3840x2160
- 应用图标/方形缩略图 →
1024x1024 - 落地页首图/OG图像 →
1536x1024 - 博客首图(5:3比例) → (两边均为16的倍数,比例=5:3)
1600x960 - 移动端/竖版插画 →
1024x1536 - 营销海报/4K素材 →
3840x2160
Quality guidance
质量指南
- for quick exploration / drafts (cheapest, fastest).
low - is a good default.
medium - only for final, ship-ready assets — significantly more expensive and can take up to ~2 minutes.
high
If the user just says "generate an image" with no signal of finality, default
to .
--quality medium- 用于快速探索/草稿(成本最低,速度最快)。
low - 是不错的默认选择。
medium - 仅用于最终、可发布的素材——成本显著更高,生成时间可达约2分钟。
high
如果用户仅说“生成一张图像”且未明确要求最终版本,默认使用。
--quality mediumPrompt-writing tips
提示词编写技巧
For best results, include in the prompt:
- Subject (what is in the image)
- Style (flat vector, watercolor, photoreal, isometric, line drawing, 3D render…)
- Composition / camera (close-up, top-down, wide shot)
- Color palette / mood
- Background (white, gradient, scene — note: does not support transparent backgrounds)
gpt-image-2 - Any text that must appear, in quotes (renders text well)
gpt-image-2
If the user gives a vague prompt, expand it with sensible defaults rather than
asking back, unless the request is genuinely ambiguous.
为获得最佳效果,提示词应包含:
- 主体(图像中的内容)
- 风格(扁平化矢量、水彩、写实、等距视角、线稿、3D渲染等)
- 构图/视角(特写、俯视、广角)
- 调色板/氛围
- 背景(白色、渐变、场景——注意:不支持透明背景)
gpt-image-2 - 必须出现的文字(用引号括起来,能很好地渲染文字)
gpt-image-2
如果用户给出模糊的提示词,请补充合理的默认值,而非反问用户,除非请求确实存在歧义。
After generating
生成后操作
- Print the output path back to the user.
- Do not embed the image in markdown — Cursor displays generated files automatically when they are written into the workspace.
- If the result is meant for a website/app, consider also running it through
an optimizer (e.g. ,
pngquant) when file size matters.cwebp
- 将输出路径告知用户。
- 不要在Markdown中嵌入图像——当图像写入工作区后,Cursor会自动显示。
- 如果生成的图像用于网站/应用,在文件大小重要的情况下,可考虑使用优化工具(如、
pngquant)进行处理。cwebp
Gather context BEFORE generating
生成前先收集上下文
Unless the user has spelled out exactly what they want (subject, style, palette,
size, destination), do a quick context-gathering pass first. The goal is for
the generated image to feel like it belongs where it's going, not like a
random asset dropped into the project. Skipping this step is the #1 way this
skill produces off-brand results.
Things to look at, in roughly this order:
-
Sibling images at the destination. If the image will live in,
public/static/blog/,public/static/marketing/, etc., open one or two existing images in that folder with the Read tool. Match their:assets/- Illustration style (3D cartoon, flat vector, photoreal, line art, isometric…)
- Color palette and lighting
- Subject conventions (e.g. "always features the product mascot", "always a metaphor, never literal screenshots", etc.)
- Aspect ratio and resolution
-
The surface that will display it. Read the relevant file:
- Blog post → read the MDX/Markdown (title, tags, opening paragraphs, key metaphors).
- Landing page section → read the component, headline, and surrounding copy.
- README → read the top of the README.
- Component → read the component to understand what it represents.
Pull the image's meaning from the actual content, not just the filename. -
Brand / design tokens. If the project has a clearly defined palette, logo, or mascot, mirror them. Quick places to check:
- for brand colors
tailwind.config.* - / theme files for CSS variables
globals.css - for logos / mascot assets
public/ - Any existing OG images or marketing assets
-
Aspect ratio / size. Pickbased on the surface: blog hero, OG image, square avatar, mobile portrait, etc. Match what's already there.
--size
Then write the prompt incorporating what you learned: subject pulled from the
content, style + palette pulled from sibling assets and brand tokens,
composition matched to the surface.
If the user did give explicit direction (style, colors, exact subject),
honor it and skip context-gathering. If they gave partial direction, gather
context for the parts they left open.
Don't ask the user clarifying questions for things you can reasonably infer
from the codebase — infer first, ask only when something is genuinely
ambiguous (e.g. two equally valid styles already exist in the project).
除非用户明确说明所有需求(主体、风格、调色板、尺寸、使用场景),否则应先快速收集上下文信息。目标是让生成的图像适配使用场景,而非像随机素材一样插入项目。跳过此步骤是本技能生成不符合品牌风格内容的最主要原因。
需查看的内容大致顺序如下:
-
目标位置的同类图像。如果图像将存放在、
public/static/blog/、public/static/marketing/等目录,请使用读取工具打开该目录中的1-2张现有图像,匹配以下内容:assets/- 插画风格(3D卡通、扁平化矢量、写实、线稿、等距视角等)
- 调色板和光影
- 主体惯例(例如“总是包含产品吉祥物”、“总是使用隐喻,从不使用文字截图”等)
- 宽高比和分辨率
-
展示图像的载体。读取相关文件:
- 博客文章 → 读取MDX/Markdown文件(标题、标签、开头段落、核心隐喻)。
- 落地页板块 → 读取组件、标题和周围文案。
- README → 读取README的开头部分。
- 组件 → 读取组件以了解其代表的内容。
从实际内容中提取图像的意义,而非仅依赖文件名。 -
品牌/设计规范。如果项目有明确的调色板、Logo或吉祥物,请予以匹配。快速检查位置:
- 中的品牌颜色
tailwind.config.* - /主题文件中的CSS变量
globals.css - 目录中的Logo/吉祥物素材
public/ - 任何现有的OG图像或营销素材
-
宽高比/尺寸。根据展示载体选择:博客首图、OG图像、方形头像、移动端竖版等。匹配现有内容的设置。
--size
然后编写包含以上信息的提示词:从内容中提取主体,从同类素材和品牌规范中提取风格+调色板,根据载体匹配构图。
如果用户已给出明确指示(风格、颜色、具体主体),请遵循指示并跳过上下文收集。如果用户给出部分指示,请为未明确的部分收集上下文。
对于可从代码库中合理推断的内容,不要向用户询问——先自行推断,仅在确实存在歧义时(例如项目中存在两种同样合理的风格)才询问用户。
Place it AND wire it up — don't just dump a file
放置并配置图像——不要仅生成文件
When the user asks for an image for a specific surface (a blog post, a landing
page, an OG card, a README, a component, etc.), you are responsible for the
whole job, not just the PNG. Always do these in order:
-
Pick the correct on-disk location for that surface. Look at what already exists and match it. Examples:
- Blog hero → wherever existing blog images live (e.g.
).
apps/<app>/public/static/blog/<slug>.png - Landing page asset → wherever other landing assets live (e.g.
).
apps/<app>/public/static/marketing/... - README / docs image → ,
docs/images/, or next to the doc.assets/ - Component-specific asset → next to the component or in its
/
public/folder.assets/
Use the file's slug, component name, or section name for the filename. Don't invent a new convention if one already exists. - Blog hero → wherever existing blog images live (e.g.
-
Wire the image up so it actually shows where the user wanted it. This is not optional. Examples:
- Blog post MDX → update the (or equivalent) frontmatter field to point at the new path. Replace any placeholder Unsplash/stock URL.
image: - Landing page section → import or reference the new asset in the relevant component/JSX.
- OG image → update the / metadata config.
<meta property="og:image"> - README → add the appropriate Markdown image tag.
- Blog post MDX → update the
-
Match existing conventions for paths (relative vsvs
/static/...), file format (png/webp/jpg), and any wrapper components (@/assets/..., customnext/image, etc.).<Image> -
Don't ask first. If the user asked for an image for a known surface, do the placement + wiring automatically and tell them what you changed at the end. Only ask when the destination is genuinely ambiguous.
当用户要求为特定载体(博客文章、落地页、OG卡片、README、组件等)生成图像时,您需要负责完整的工作,而非仅生成PNG文件。请始终按以下步骤操作:
-
选择正确的磁盘位置。查看现有文件的存放位置并遵循相同规则。示例:
- 博客首图 → 现有博客图像的存放位置(例如)。
apps/<app>/public/static/blog/<slug>.png - 落地页素材 → 其他落地页素材的存放位置(例如)。
apps/<app>/public/static/marketing/... - README/文档图像 → 、
docs/images/或文档旁。assets/ - 组件专属素材 → 组件旁或其/
public/目录中。assets/
使用文件的slug、组件名称或板块名称作为文件名。如果已有命名规则,请勿自行创建新规则。 - 博客首图 → 现有博客图像的存放位置(例如
-
配置图像使其正常显示。这是必须完成的步骤。示例:
- 博客文章MDX → 更新(或等效的)前置字段,指向新路径。替换任何占位的Unsplash/图库URL。
image: - 落地页板块 → 在相关组件/JSX中导入或引用新素材。
- OG图像 → 更新/元数据配置。
<meta property="og:image"> - README → 添加适当的Markdown图像标签。
- 博客文章MDX → 更新
-
匹配现有规范包括路径(相对路径//
/static/...)、文件格式(png/webp/jpg)和任何包装组件(@/assets/...、自定义next/image等)。<Image> -
不要先询问用户。如果用户要求为已知载体生成图像,请自动完成放置和配置操作,并在最后告知用户您所做的更改。仅在目标位置确实存在歧义时才询问用户。
Errors — surface, don't hide
错误处理——直接告知,不要隐藏
If any of the following happen, stop immediately and report the error to
the user. Do not retry, do not change the model, do not change the prompt.
- → ask the user how to provide it.
OPENAI_API_KEY is not set - → tell the user to run
openai package not installed.pip install --upgrade openai - 403 "organization must be verified" → tell the user to verify at platform.openai.com/settings/organization/general. Do not switch models.
- 400 size error → report it; let the user pick a valid size.
- 400 about transparent background → report it; doesn't support transparency.
gpt-image-2 - Any other API error → report verbatim and stop.
如果发生以下任何情况,请立即停止并向用户报告错误。不要重试,不要切换模型,不要修改提示词。
- → 询问用户提供密钥的方式。
OPENAI_API_KEY is not set - → 告知用户运行
openai package not installed。pip install --upgrade openai - 403错误提示“organization must be verified” → 告知用户前往platform.openai.com/settings/organization/general完成验证。不要切换模型。
- 400尺寸错误 → 报告错误;让用户选择有效的尺寸。
- 400透明背景相关错误 → 报告错误;不支持透明背景。
gpt-image-2 - 任何其他API错误 → 原封不动报告并停止操作。