npx skills add ...
npx skills add openai/codex --skill imagegen
npx skills add openai/codex --skill imagegen
Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extending an established icon or logo system, or building the visual directly in HTML/CSS/canvas.
Generates or edits images for the current project (for example website assets, game assets, UI mockups, product mockups, wireframes, logo design, photorealistic images, or infographics).
This skill has exactly two top-level modes:
image_gen tool for normal image generation, editing, and simple transparent-image requests. Does not require OPENAI_API_KEY.scripts/image_gen.py CLI. Use when the user explicitly asks for the CLI/API/model path, or after the user explicitly confirms a true model-native transparency fallback with gpt-image-1.5. Requires OPENAI_API_KEY.Within CLI fallback, the CLI exposes three subcommands:
generateeditgenerate-batchRules:
image_gen tool by default for normal image generation and editing requests.image_gen first: prompt for a flat removable chroma-key background, then remove it locally with the installed helper at $CODEX_HOME/skills/.system/imagegen/scripts/remove_chroma_key.py.image_gen or CLI gpt-image-2 to CLI gpt-image-1.5. Treat this as a model/path downgrade and ask the user before doing it, unless the user has already explicitly requested gpt-image-1.5, scripts/image_gen.py, or CLI fallback.gpt-image-1.5 --background transparent --output-format png because gpt-image-2 does not support background=transparent, then ask whether to proceed. Run the CLI fallback only after the user confirms.batch by itself does not mean CLI fallback. If the user asks for many assets or says to batch-generate assets without explicitly asking for CLI/API/model controls, stay on the built-in path and issue one built-in call per requested asset or variant.OPENAI_API_KEY. Proceed only if the user explicitly asks for that fallback.scripts/image_gen.py workflow. Do not create one-off SDK runners.scripts/image_gen.py. If something is missing, ask the user before doing anything else.Built-in save-path policy:
$CODEX_HOME/* by default.image_gen tool. If a specific location is needed, generate first and then move or copy the selected output from $CODEX_HOME/generated_images/....$CODEX_HOME/* path.$CODEX_HOME/* path.hero-v2.png or item-icon-edited.png.Shared prompt guidance for both modes lives in references/prompting.md and references/sample-prompts.md.
Fallback-only docs/resources for CLI mode:
references/cli.mdreferences/image-api.mdreferences/codex-network.mdscripts/image_gen.pyLocal post-processing helper:
$CODEX_HOME/skills/.system/imagegen/scripts/remove_chroma_key.py: removes a flat chroma-key background from a generated image and writes a PNG/WebP with alpha. Prefer auto-key sampling, soft matte, and despill for antialiased edges.Think about two separate questions:
Intent:
Built-in edit semantics:
view_image tool so the image is visible in the conversation context, then proceed with the built-in edit flow.Execution strategy:
image_gen call per requested asset or variant.generate-batch subcommand only when the user explicitly chose CLI mode and needs many prompts/assets.n as a substitute for separate prompts. n is for variants of one prompt; distinct assets need distinct built-in calls or distinct CLI generate-batch jobs.Assume the user wants a new image unless they clearly ask to change an existing one.
generate or edit.generate-batch.view_image first so the image is available in conversation context.image_gen rather than substituting SVG/HTML/CSS placeholders. If the request is for an icon, logo, or UI graphic that should match existing repo-native SVG/vector/code assets, prefer editing those directly instead.image_gen tool by default.image_gen on a flat chroma-key background, copy the selected output into the workspace or tmp/imagegen/, run the installed $CODEX_HOME/skills/.system/imagegen/scripts/remove_chroma_key.py helper, and validate the alpha result before using it. If this path looks unsuitable or fails, ask before switching to CLI gpt-image-1.5.$CODEX_HOME/generated_images/... path.$CODEX_HOME/generated_images/... path.input_fidelity, masks, output format, output paths, and network setup.Transparent-image requests still use built-in image_gen first. Because the built-in tool does not expose a true transparent-background control, create a removable chroma-key source image and then convert the key color to alpha locally.
Default sequence:
image_gen to generate the requested subject on a perfectly flat solid chroma-key background.#00ff00, use #ff00ff for green subjects, and avoid #0000ff for blue subjects.$CODEX_HOME/generated_images/... into the workspace or tmp/imagegen/.--edge-contract 1; use --edge-feather 0.25 only when the edge is visibly stair-stepped and the subject is not shiny or reflective.$CODEX_HOME/*.Prompt transparent requests like this:
Do not automatically use CLI gpt-image-1.5 --background transparent --output-format png instead of chroma keying. Ask the user first when the user asks for true/native transparency, when local removal fails validation, or when the requested image is complex: hair, fur, feathers, smoke, glass, liquids, translucent materials, reflective objects, soft shadows, realistic product grounding, or subject colors that conflict with all practical key colors.
Use a concise confirmation like:
Reformat user prompts into a structured, production-oriented spec. Make the user's goal clearer and more actionable, but do not blindly add detail.
Treat this as prompt-shaping guidance, not a closed schema. Use only the lines that help, and add a short extra labeled line when it materially improves clarity.
Use the user's prompt specificity to decide how much augmentation is appropriate:
Allowed augmentations:
Not allowed augmentations:
Classify each request into one of these buckets and keep the slug consistent across prompts and references.
Generate:
Edit:
image_gen with chroma-key removal first for simple opaque subjects; ask before using CLI true transparency for complex subjects.Use the following labeled spec as shared prompt scaffolding for both top-level modes:
Notes:
Asset type and Input images are prompt scaffolding, not dedicated CLI flags.Scene/backdrop refers to the visual setting. It is not the same as the fallback CLI background parameter, which controls output transparency behavior.Quality:, Input fidelity:, masks, output format, and output paths belong in the CLI path only. Do not treat them as built-in image_gen tool arguments.Augmentation rules:
change only X; keep Y unchanged).references/cli.md and references/image-api.md for model, quality, input_fidelity, masks, output format, and output-path guidance.gpt-image-1.5.More principles shared by both modes: references/prompting.md.
Copy/paste specs shared by both modes: references/sample-prompts.md.
Asset-type templates (website assets, game assets, wireframes, logo) are consolidated in references/sample-prompts.md.
The fallback CLI defaults to gpt-image-2.
gpt-image-2 for new CLI/API workflows unless the request needs true model-native transparent output.gpt-image-1.5 unless the user already explicitly requested gpt-image-1.5, scripts/image_gen.py, or CLI fallback. Explain that the built-in chroma-key path is the default, but true transparency requires gpt-image-1.5 because gpt-image-2 does not support background=transparent.gpt-image-2 always uses high fidelity for image inputs; do not set input_fidelity with this model.gpt-image-2 supports quality values low, medium, high, and auto.quality low for fast drafts, thumbnails, and quick iterations. Use medium, high, or auto for final assets, dense text, diagrams, identity-sensitive edits, or high-resolution outputs.1024x1024 for fast square drafts.3840x2160 for landscape or 2160x3840 for portrait.gpt-image-2 size may be auto or WIDTHxHEIGHT if all constraints hold: max edge <= 3840px, both edges multiples of 16px, long-to-short ratio <= 3:1, total pixels between 655,360 and 8,294,400.Popular gpt-image-2 sizes:
1024x1024 square1536x1024 landscape1024x1536 portrait2048x2048 2K square2048x1152 2K landscape3840x2160 4K landscape2160x3840 4K portraitautoThese conventions apply only to the CLI fallback. They do not describe built-in image_gen output behavior.
tmp/imagegen/ for intermediate files (for example JSONL batches); delete them when done.output/imagegen/.--out or --out-dir to control output paths; keep filenames stable and descriptive.Prefer uv for dependency management in this repo.
Required Python package:
Required for local chroma-key removal and optional downscaling:
Portability note:
uv pip install ... remains the preferred path.OPENAI_API_KEY must be set for live API calls.OPENAI_API_KEY when using the built-in image_gen tool.If the key is missing, give the user these steps:
OPENAI_API_KEY as an environment variable in their system.If installation is not possible in this environment, tell the user which dependency is missing and how to install it into their active environment.
references/cli.mdreferences/image-api.mdreferences/codex-network.mdreferences/prompting.md: shared prompting principles for both modes.references/sample-prompts.md: shared copy/paste prompt recipes for both modes.references/cli.md: fallback-only CLI usage via scripts/image_gen.py.references/image-api.md: fallback-only API/CLI parameter reference.references/codex-network.md: fallback-only network/sandbox troubleshooting for CLI mode.scripts/image_gen.py: fallback-only CLI implementation. Do not load or use it unless the user explicitly chooses CLI mode or explicitly confirms a transparent request's true CLI transparency fallback.$CODEX_HOME/skills/.system/imagegen/scripts/remove_chroma_key.py: local post-processing helper for built-in transparent-image requests.