ranger-image-2
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRanger Image 2
Ranger Image 2
Use this skill to generate raster images through an OpenAI-compatible Image API with .
gpt-image-2使用本技能通过兼容OpenAI的图像API,借助生成光栅图像。
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.
- 按以下顺序解析凭证:优先使用环境变量,其次是,当终端可用时,最后使用交互式
~/.codex/ranger-image-2/config.json提示。--configure - 除非得到用户明确确认,否则切勿在用户本地Codex配置文件以外的任何地方回显、提交或写入API密钥。
- 优先使用,而非手动编写一次性API调用程序。
scripts/generate_image.py - 当用户认为Codex CLI的会话提取技能过慢而拒绝使用时,优先选择API路由以提升速度。
--enable image_generation - 如果设置为类似
CUSTOM_IMAGE_URL的路径,将同源地址标准化为https://host/api/image/generate并调用https://host/v1;经观察,此工作区中/v1/images/generations会返回404错误,而/api/image/generate路由可正常工作。/v1 - 除非用户要求优化提示词,否则需完全保留用户的提示词内容。
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.
如果缺少以及或,请运行:
OPENAI_API_KEYOPENAI_BASE_URLCUSTOM_IMAGE_URLpowershell
python skills/ranger-image-2/scripts/generate_image.py --configure该脚本会询问缺失的值,隐藏API密钥输入,并可将这些值持久化保存至:
text
~/.codex/ranger-image-2/config.json环境变量始终会覆盖此本地配置。请勿提交该配置文件。
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_URLpowershell
python skills/ranger-image-2/scripts/generate_image.py `
--prompt "Create a sunset afterglow..." `
--out output/imagegen/sunset.png `
--size 1536x1024 `
--quality high `
--force运行前请在shell环境中设置凭证和端点值。如果已设置,脚本会直接使用该值。否则,它会从中提取服务源并加上来生成地址。
OPENAI_BASE_URLCUSTOM_IMAGE_URL/v1Workflow
工作流程
- 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.
- 运行进行低成本的配置检查。
scripts/generate_image.py --dry-run - 如果缺少凭证或端点且交互式终端可用,请运行,让用户提供值;仅在确认后进行持久化保存。
scripts/generate_image.py --configure - 将较长的提示词保存到临时提示词文件中,以避免shell引用问题。
- 使用或
--prompt-file参数运行--prompt,除非用户指定了其他路径,否则选择scripts/generate_image.py下的工作区输出路径。output/imagegen/ - 验证保存的文件:检查文件是否存在、字节大小是否非零以及尺寸是否符合要求。
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()
}PowerShell图像尺寸检查:
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
- 返回
/api/image/generate:通过设置404 page not found,使用同一主机的OPENAI_BASE_URL=https://host/v1路由。/v1/images/generations - 出现TLS错误:使用捆绑的脚本/OpenAI SDK路径,而非原生
urllib。urllib - 非交互式运行中缺少凭证:设置环境变量,或在终端中运行。
python skills/ranger-image-2/scripts/generate_image.py --configure - :在当前环境中运行
openai SDK is not installed。python -m pip install openai - 输出路径已存在:传递参数或选择新的文件名。
--force