ranger-image-2

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Ranger 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-2
生成光栅图像。

Rules

规则

  • Resolve credentials in this order: environment variables first, then
    ~/.codex/ranger-image-2/config.json
    , then interactive
    --configure
    prompts when a terminal is available.
  • Never echo, commit, or write API keys anywhere except the user-local Codex config file after explicit confirmation.
  • Prefer
    scripts/generate_image.py
    instead of hand-writing one-off API callers.
  • Use the API route for speed when the user rejects the Codex CLI
    --enable image_generation
    session-extraction skill as too slow.
  • If
    CUSTOM_IMAGE_URL
    is set to a path such as
    https://host/api/image/generate
    , normalize the same origin to
    https://host/v1
    and call
    /v1/images/generations
    ; this workspace observed
    /api/image/generate
    returning 404 while
    /v1
    routes worked.
  • Keep the user's prompt verbatim unless they ask for prompt polishing.
  • 按以下顺序解析凭证:优先使用环境变量,其次是
    ~/.codex/ranger-image-2/config.json
    ,当终端可用时,最后使用交互式
    --configure
    提示。
  • 除非得到用户明确确认,否则切勿在用户本地Codex配置文件以外的任何地方回显、提交或写入API密钥。
  • 优先使用
    scripts/generate_image.py
    ,而非手动编写一次性API调用程序。
  • 当用户认为Codex CLI的
    --enable image_generation
    会话提取技能过慢而拒绝使用时,优先选择API路由以提升速度。
  • 如果
    CUSTOM_IMAGE_URL
    设置为类似
    https://host/api/image/generate
    的路径,将同源地址标准化为
    https://host/v1
    并调用
    /v1/images/generations
    ;经观察,此工作区中
    /api/image/generate
    会返回404错误,而
    /v1
    路由可正常工作。
  • 除非用户要求优化提示词,否则需完全保留用户的提示词内容。

One-time configuration

一次性配置

If
OPENAI_API_KEY
plus
OPENAI_BASE_URL
or
CUSTOM_IMAGE_URL
are missing, run:
powershell
python skills/ranger-image-2/scripts/generate_image.py --configure
The script asks for missing values, hides API-key input, and can persist them to:
text
~/.codex/ranger-image-2/config.json
Environment variables always override this local config. Do not commit the config file.
如果缺少
OPENAI_API_KEY
以及
OPENAI_BASE_URL
CUSTOM_IMAGE_URL
,请运行:
powershell
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 `
  --force
Set credentials and endpoint values in the shell environment before running. If
OPENAI_BASE_URL
is already set, the script uses it directly. Otherwise it derives the provider origin plus
/v1
from
CUSTOM_IMAGE_URL
.
powershell
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_URL
,脚本会直接使用该值。否则,它会从
CUSTOM_IMAGE_URL
中提取服务源并加上
/v1
来生成地址。

Workflow

工作流程

  1. Run
    scripts/generate_image.py --dry-run
    for a cheap configuration check.
  2. If credentials or endpoint are missing and an interactive terminal is available, run
    scripts/generate_image.py --configure
    and let the user provide values; persist only after confirmation.
  3. Save long prompts to a temporary prompt file to avoid shell quoting issues.
  4. Run
    scripts/generate_image.py
    with
    --prompt-file
    or
    --prompt
    , choosing a workspace output path under
    output/imagegen/
    unless the user specified another path.
  5. Validate the saved file: existence, non-zero byte size, and dimensions.
  1. 运行
    scripts/generate_image.py --dry-run
    进行低成本的配置检查。
  2. 如果缺少凭证或端点且交互式终端可用,请运行
    scripts/generate_image.py --configure
    ,让用户提供值;仅在确认后进行持久化保存。
  3. 将较长的提示词保存到临时提示词文件中,以避免shell引用问题。
  4. 使用
    --prompt-file
    --prompt
    参数运行
    scripts/generate_image.py
    ,除非用户指定了其他路径,否则选择
    output/imagegen/
    下的工作区输出路径。
  5. 验证保存的文件:检查文件是否存在、字节大小是否非零以及尺寸是否符合要求。

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

故障排除

  • 404 page not found
    on
    /api/image/generate
    : use the same host's
    /v1/images/generations
    route by deriving
    OPENAI_BASE_URL=https://host/v1
    .
  • TLS errors from
    urllib
    : use the bundled script/OpenAI SDK path instead of raw
    urllib
    .
  • Missing credentials in a non-interactive run: set environment variables or run
    python skills/ranger-image-2/scripts/generate_image.py --configure
    in a terminal.
  • openai SDK is not installed
    : run
    python -m pip install openai
    in the active environment.
  • Existing output path: pass
    --force
    or choose a new filename.
  • /api/image/generate
    返回
    404 page not found
    :通过设置
    OPENAI_BASE_URL=https://host/v1
    ,使用同一主机的
    /v1/images/generations
    路由。
  • urllib
    出现TLS错误:使用捆绑的脚本/OpenAI SDK路径,而非原生
    urllib
  • 非交互式运行中缺少凭证:设置环境变量,或在终端中运行
    python skills/ranger-image-2/scripts/generate_image.py --configure
  • openai SDK is not installed
    :在当前环境中运行
    python -m pip install openai
  • 输出路径已存在:传递
    --force
    参数或选择新的文件名。