This file is for the fallback CLI mode only.
scripts/image_gen.py)This file is for the fallback CLI mode only. Read it only after the user explicitly asks to use scripts/image_gen.py instead of the built-in image_gen tool.
generate-batch is a CLI subcommand in this fallback path. It is not a top-level mode of the skill.
generate: generate a new image from a promptedit: edit one or more existing imagesgenerate-batch: run many generation jobs from a JSONL fileReal API calls require network access + OPENAI_API_KEY. --dry-run does not.
Set a stable path to the skill CLI (default CODEX_HOME is ~/.codex):
export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
export IMAGE_GEN="$CODEX_HOME/skills/.system/imagegen/scripts/image_gen.py"
Install dependencies into that environment with its package manager. In uv-managed environments, uv pip install ... remains the preferred path.
Dry-run (no API call; no network required; does not require the openai package):
python "$IMAGE_GEN" generate \
--prompt "Test" \
--out output/imagegen/test.png \
--dry-run
Notes:
output/imagegen/.Generate (requires OPENAI_API_KEY + network):
python "$IMAGE_GEN" generate \
--prompt "A cozy alpine cabin at dawn" \
--size 1024x1024 \
--out output/imagegen/alpine-cabin.png
Edit:
python "$IMAGE_GEN" edit \
--image input.png \
--prompt "Replace only the background with a warm sunset" \
--out output/imagegen/sunset-edit.png
python "$IMAGE_GEN" ...) after activating the correct environment.gen_images.py) unless the user explicitly asks for a custom wrapper.scripts/image_gen.py. If something is missing, ask the user before doing anything else.gpt-image-1.5gpt-image-*)1024x1024autopngoutput/imagegen/output.png--background is setThese are explicit CLI controls. They are not built-in image_gen tool arguments.
--quality works for generate, edit, and generate-batch: low|medium|high|auto--input-fidelity is edit-only and validated as low|high--mask is edit-onlyExample:
python "$IMAGE_GEN" edit \
--image input.png \
--prompt "Change only the background" \
--quality high \
--input-fidelity high \
--out output/imagegen/background-edit.png
Mask notes:
--image flags. Their order is meaningful, so describe each image by index and role in the prompt.--mask.change only the background; keep the subject unchanged) to reduce drift.tmp/imagegen/ for temporary JSONL inputs or scratch files.output/imagegen/ for final outputs.--force.--out-dir changes one-off naming to image_1.<ext>, image_2.<ext>, and so on.-web unless you override it.Generate with augmentation fields:
python "$IMAGE_GEN" generate \
--prompt "A minimal hero image of a ceramic coffee mug" \
--use-case "product-mockup" \
--style "clean product photography" \
--composition "wide product shot with usable negative space for page copy" \
--constraints "no logos, no text" \
--out output/imagegen/mug-hero.png
Generate + also write a downscaled copy for fast web loading:
python "$IMAGE_GEN" generate \
--prompt "A cozy alpine cabin at dawn" \
--size 1024x1024 \
--downscale-max-dim 1024 \
--out output/imagegen/alpine-cabin.png
Generate multiple prompts concurrently (async batch):
mkdir -p tmp/imagegen output/imagegen/batch
cat > tmp/imagegen/prompts.jsonl << 'EOF'
{"prompt":"Cavernous hangar interior with a compact shuttle parked near the center","use_case":"stylized-concept","composition":"wide-angle, low-angle","lighting":"volumetric light rays through drifting fog","constraints":"no logos or trademarks; no watermark","size":"1536x1024"}
{"prompt":"Gray wolf in profile in a snowy forest","use_case":"photorealistic-natural","composition":"eye-level","constraints":"no logos or trademarks; no watermark","size":"1024x1024"}
EOF
python "$IMAGE_GEN" generate-batch \
--input tmp/imagegen/prompts.jsonl \
--out-dir output/imagegen/batch \
--concurrency 5
rm -f tmp/imagegen/prompts.jsonl
Notes:
generate-batch requires --out-dir.--concurrency to control parallelism (default 5).size, quality, background, output_format, output_compression, moderation, n, model, out, and prompt-augmentation fields).--n generates multiple variants for a single prompt; generate-batch is for many different prompts.out is treated as a filename under --out-dir.1024x1024, 1536x1024, 1024x1536, or auto.output_format to be png or webp.--prompt-file, --output-compression, --moderation, --max-attempts, --fail-fast, --force, and --no-augment are supported.references/image-api.mdreferences/sample-prompts.mdreferences/codex-network.md