ranger-image-2
Original:🇺🇸 English
Translated
1 scriptsChecked / no sensitive code detected
Generate images with gpt-image-2 through an OpenAI-compatible Image API using the current OPENAI_API_KEY, OPENAI_BASE_URL, or CUSTOM_IMAGE_URL environment variables. Use when the user asks to call gpt-image-2 via API/CLI, /v1/images/generations, the prior /api/image/generate endpoint flow, or wants the faster API route instead of Codex CLI image_generation/session extraction.
6installs
Added on
NPX Install
npx skill4agent add ranger1112/ranger-image-skills ranger-image-2Tags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Ranger Image 2
Use this skill to generate raster images through an OpenAI-compatible Image API with .
gpt-image-2Rules
- Resolve credentials in this order: environment variables first, then , then interactive
~/.codex/ranger-image-2/config.jsonprompts when a terminal is available.--configure - Never echo, commit, or write API keys anywhere except the user-local Codex config file after explicit confirmation.
- Prefer instead of hand-writing one-off API callers.
scripts/generate_image.py - Use the API route for speed when the user rejects the Codex CLI session-extraction skill as too slow.
--enable image_generation - If is set to a path such as
CUSTOM_IMAGE_URL, normalize the same origin tohttps://host/api/image/generateand callhttps://host/v1; this workspace observed/v1/images/generationsreturning 404 while/api/image/generateroutes worked./v1 - Keep the user's prompt verbatim unless they ask for prompt polishing.
One-time configuration
If plus or are missing, run:
OPENAI_API_KEYOPENAI_BASE_URLCUSTOM_IMAGE_URLpowershell
python skills/ranger-image-2/scripts/generate_image.py --configureThe script asks for missing values, hides API-key input, and can persist them to:
text
~/.codex/ranger-image-2/config.jsonEnvironment variables always override this local config. Do not commit the config file.
Quick start
powershell
python skills/ranger-image-2/scripts/generate_image.py `
--prompt "Create a sunset afterglow..." `
--out output/imagegen/sunset.png `
--size 1536x1024 `
--quality high `
--forceSet credentials and endpoint values in the shell environment before running. If is already set, the script uses it directly. Otherwise it derives the provider origin plus from .
OPENAI_BASE_URL/v1CUSTOM_IMAGE_URLWorkflow
- Run for a cheap configuration check.
scripts/generate_image.py --dry-run - If credentials or endpoint are missing and an interactive terminal is available, run and let the user provide values; persist only after confirmation.
scripts/generate_image.py --configure - Save long prompts to a temporary prompt file to avoid shell quoting issues.
- Run with
scripts/generate_image.pyor--prompt-file, choosing a workspace output path under--promptunless the user specified another path.output/imagegen/ - Validate the saved file: existence, non-zero byte size, and dimensions.
Validation snippets
PowerShell image dimension check:
powershell
Add-Type -AssemblyName System.Drawing
$path = 'output/imagegen/result.png'
$item = Get-Item -LiteralPath $path
$img = [System.Drawing.Image]::FromFile((Resolve-Path $path).Path)
try {
[pscustomobject]@{
Path = $path
Bytes = $item.Length
Dimensions = "$($img.Width)x$($img.Height)"
} | ConvertTo-Json -Compress
} finally {
$img.Dispose()
}Troubleshooting
- on
404 page not found: use the same host's/api/image/generateroute by deriving/v1/images/generations.OPENAI_BASE_URL=https://host/v1 - TLS errors from : use the bundled script/OpenAI SDK path instead of raw
urllib.urllib - Missing credentials in a non-interactive run: set environment variables or run in a terminal.
python skills/ranger-image-2/scripts/generate_image.py --configure - : run
openai SDK is not installedin the active environment.python -m pip install openai - Existing output path: pass or choose a new filename.
--force