generate-image
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGenerate 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-previewPrerequisites
前提条件
- environment variable must be set
OPENROUTER_API_KEY - available via npx
tsx
- 必须设置环境变量
OPENROUTER_API_KEY - 可通过npx使用
tsx
Usage
使用方法
Run the script via :
npx tsxbash
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 tsxbash
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
参数说明
| Param | Required | Default | Description |
|---|---|---|---|
| Yes | - | Image description |
| No | | OpenRouter model ID |
| No | 1024 | Image width |
| No | 1024 | Image height |
| No | auto (timestamp-slug.png) | Output filename |
| No | | Output directory |
| No | - | HTTP proxy URL |
| 参数 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | - | 图片描述 |
| 否 | | OpenRouter模型ID |
| 否 | 1024 | 图片宽度 |
| 否 | 1024 | 图片高度 |
| 否 | 自动生成(时间戳-slug.png) | 输出文件名 |
| 否 | | 输出目录 |
| 否 | - | HTTP代理地址 |
Supported Models
支持的模型
- (default, recommended)
google/gemini-3.1-flash-image-preview black-forest-labs/flux-1.1-problack-forest-labs/flux-schnell- Any OpenRouter model that supports image generation
- (默认,推荐使用)
google/gemini-3.1-flash-image-preview black-forest-labs/flux-1.1-problack-forest-labs/flux-schnell- 任何支持图片生成的OpenRouter模型
How to Use as an Agent
如何作为Agent使用
When the user asks you to generate an image:
- Compose a detailed English prompt describing the desired image
- Choose appropriate model and size for the use case
- Run the script using Bash tool
- The script outputs the saved file path to stdout — use this path to reference the image in code or tell the user
当用户要求你生成图片时:
- 撰写详细的英文描述来定义所需图片
- 根据使用场景选择合适的模型和尺寸
- 使用Bash工具运行该脚本
- 脚本会将保存的文件路径输出到标准输出——你可以使用这个路径在代码中引用图片,或者告知用户
Quick Examples
快速示例
bash
undefinedbash
undefinedSimple generation with defaults
使用默认参数的简单生成
npx tsx generate-image.ts
--prompt "a minimalist logo of a mountain with a sun, flat design, blue and orange"
--prompt "a minimalist logo of a mountain with a sun, flat design, blue and orange"
npx tsx generate-image.ts
--prompt "极简风格的山与太阳标志,扁平化设计,蓝橙配色"
--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"
--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"
--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"
--prompt "pixel art cat sitting on a desk"
--proxy "http://127.0.0.1:7890"
undefinedundefinedTroubleshooting
故障排除
- No API key: Set env var. Get key at https://openrouter.ai/keys
OPENROUTER_API_KEY - Proxy issues: Ensure proxy URL is correct and proxy is running
- Model not found: Check available models at https://openrouter.ai/models
- 无API密钥:设置环境变量。可在https://openrouter.ai/keys获取密钥
OPENROUTER_API_KEY - 代理问题:确保代理地址正确且代理正在运行
- 模型未找到:查看https://openrouter.ai/models获取可用模型列表