generate-image

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Generate Image via OpenRouter

通过OpenRouter生成图片

Generate images using OpenRouter's image models from the command line. Default model:
google/gemini-3.1-flash-image-preview
.
使用OpenRouter的图像模型从命令行生成图片。默认模型:
google/gemini-3.1-flash-image-preview

Prerequisites

前提条件

  • OPENROUTER_API_KEY
    environment variable must be set
  • tsx
    available via npx
  • 必须设置
    OPENROUTER_API_KEY
    环境变量
  • 可通过npx使用
    tsx

Usage

使用方法

Run the script via
npx tsx
:
bash
npx tsx generate-image.ts \
  --prompt "description of the image" \
  --model "google/gemini-3.1-flash-image-preview" \
  --width 1024 --height 1024 \
  --output "filename.png" \
  --dir "./generated-images" \
  --proxy "http://127.0.0.1:7890"
通过
npx tsx
运行脚本:
bash
npx tsx generate-image.ts \
  --prompt "图片描述" \
  --model "google/gemini-3.1-flash-image-preview" \
  --width 1024 --height 1024 \
  --output "文件名.png" \
  --dir "./generated-images" \
  --proxy "http://127.0.0.1:7890"

Parameters

参数说明

ParamRequiredDefaultDescription
--prompt
Yes-Image description
--model
No
google/gemini-3.1-flash-image-preview
OpenRouter model ID
--width
No1024Image width
--height
No1024Image height
--output
Noauto (timestamp-slug.png)Output filename
--dir
No
./generated-images
Output directory
--proxy
No-HTTP proxy URL
参数是否必填默认值描述
--prompt
-图片描述
--model
google/gemini-3.1-flash-image-preview
OpenRouter模型ID
--width
1024图片宽度
--height
1024图片高度
--output
自动生成(时间戳-slug.png)输出文件名
--dir
./generated-images
输出目录
--proxy
-HTTP代理地址

Supported Models

支持的模型

  • google/gemini-3.1-flash-image-preview
    (default, recommended)
  • black-forest-labs/flux-1.1-pro
  • black-forest-labs/flux-schnell
  • Any OpenRouter model that supports image generation
  • google/gemini-3.1-flash-image-preview
    (默认,推荐使用)
  • black-forest-labs/flux-1.1-pro
  • black-forest-labs/flux-schnell
  • 任何支持图片生成的OpenRouter模型

How to Use as an Agent

如何作为Agent使用

When the user asks you to generate an image:
  1. Compose a detailed English prompt describing the desired image
  2. Choose appropriate model and size for the use case
  3. Run the script using Bash tool
  4. The script outputs the saved file path to stdout — use this path to reference the image in code or tell the user
当用户要求你生成图片时:
  1. 撰写详细的英文描述来定义所需图片
  2. 根据使用场景选择合适的模型和尺寸
  3. 使用Bash工具运行该脚本
  4. 脚本会将保存的文件路径输出到标准输出——你可以使用这个路径在代码中引用图片,或者告知用户

Quick Examples

快速示例

bash
undefined
bash
undefined

Simple generation with defaults

使用默认参数的简单生成

npx tsx generate-image.ts
--prompt "a minimalist logo of a mountain with a sun, flat design, blue and orange"
npx tsx generate-image.ts
--prompt "极简风格的山与太阳标志,扁平化设计,蓝橙配色"

With specific model and output

指定模型和输出的示例

npx tsx generate-image.ts
--prompt "abstract gradient background, purple to blue"
--model "black-forest-labs/flux-1.1-pro"
--output "bg-gradient.png"
--dir "./public/images"
npx tsx generate-image.ts
--prompt "抽象渐变背景,从紫色过渡到蓝色"
--model "black-forest-labs/flux-1.1-pro"
--output "bg-gradient.png"
--dir "./public/images"

With proxy

使用代理的示例

npx tsx generate-image.ts
--prompt "pixel art cat sitting on a desk"
--proxy "http://127.0.0.1:7890"
undefined
npx tsx generate-image.ts
--prompt "像素风格的猫坐在桌子上"
--proxy "http://127.0.0.1:7890"
undefined

Troubleshooting

故障排除