generate-image

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Generate Image

生成图片

Generate and edit high-quality images using OpenRouter's image generation models including FLUX.2 Pro and Gemini 3 Pro.
使用OpenRouter的图片生成模型(包括FLUX.2 Pro和Gemini 3 Pro)生成和编辑高质量图片。

When to Use This Skill

何时使用本技能

Use generate-image for:
  • Photos and photorealistic images
  • Artistic illustrations and artwork
  • Concept art and visual concepts
  • Visual assets for presentations or documents
  • Image editing and modifications
  • Any general-purpose image generation needs
Use scientific-schematics instead for:
  • Flowcharts and process diagrams
  • Circuit diagrams and electrical schematics
  • Biological pathways and signaling cascades
  • System architecture diagrams
  • CONSORT diagrams and methodology flowcharts
  • Any technical/schematic diagrams
适用场景(使用generate-image):
  • 照片和写实风格图片
  • 艺术插画和艺术品
  • 概念艺术和视觉概念
  • 演示文稿或文档的视觉资产
  • 图片编辑与修改
  • 任何通用图片生成需求
适用场景(改用scientific-schematics):
  • 流程图和过程图
  • 电路图和电气原理图
  • 生物通路和信号级联图
  • 系统架构图
  • CONSORT图和方法学流程图
  • 任何技术/原理图

Quick Start

快速开始

Use the
scripts/generate_image.py
script to generate or edit images:
bash
undefined
使用
scripts/generate_image.py
脚本生成或编辑图片:
bash
undefined

Generate a new image

Generate a new image

python scripts/generate_image.py "A beautiful sunset over mountains"
python scripts/generate_image.py "A beautiful sunset over mountains"

Edit an existing image

Edit an existing image

python scripts/generate_image.py "Make the sky purple" --input photo.jpg

This generates/edits an image and saves it as `generated_image.png` in the current directory.
python scripts/generate_image.py "Make the sky purple" --input photo.jpg

此脚本会生成/编辑图片,并将其保存为当前目录下的`generated_image.png`文件。

API Key Setup

API密钥设置

CRITICAL: The script requires an OpenRouter API key. Before running, check if the user has configured their API key:
  1. Look for a
    .env
    file in the project directory or parent directories
  2. Check for
    OPENROUTER_API_KEY=<key>
    in the
    .env
    file
  3. If not found, inform the user they need to:
    • Create a
      .env
      file with
      OPENROUTER_API_KEY=your-api-key-here
    • Or set the environment variable:
      export OPENROUTER_API_KEY=your-api-key-here
    • Get an API key from: https://openrouter.ai/keys
The script will automatically detect the
.env
file and provide clear error messages if the API key is missing.
重要提示:该脚本需要OpenRouter API密钥。运行前,请检查用户是否已配置API密钥:
  1. 在项目目录或父目录中查找
    .env
    文件
  2. 检查
    .env
    文件中是否存在
    OPENROUTER_API_KEY=<key>
    配置
  3. 如果未找到,请告知用户需要:
    • 创建
      .env
      文件并添加
      OPENROUTER_API_KEY=your-api-key-here
    • 或设置环境变量:
      export OPENROUTER_API_KEY=your-api-key-here
    • 从以下地址获取API密钥:https://openrouter.ai/keys
脚本会自动检测
.env
文件,如果缺少API密钥,会提供清晰的错误提示信息。

Model Selection

模型选择

Default model:
google/gemini-3-pro-image-preview
(high quality, recommended)
Available models for generation and editing:
  • google/gemini-3-pro-image-preview
    - High quality, supports generation + editing
  • black-forest-labs/flux.2-pro
    - Fast, high quality, supports generation + editing
Generation only:
  • black-forest-labs/flux.2-flex
    - Fast and cheap, but not as high quality as pro
Select based on:
  • Quality: Use gemini-3-pro or flux.2-pro
  • Editing: Use gemini-3-pro or flux.2-pro (both support image editing)
  • Cost: Use flux.2-flex for generation only
默认模型
google/gemini-3-pro-image-preview
(高质量,推荐使用)
支持生成和编辑的可用模型
  • google/gemini-3-pro-image-preview
    - 高质量,支持生成+编辑
  • black-forest-labs/flux.2-pro
    - 速度快、质量高,支持生成+编辑
仅支持生成的模型
  • black-forest-labs/flux.2-flex
    - 速度快、成本低,但质量不如Pro版本
选择模型的依据:
  • 质量:使用gemini-3-pro或flux.2-pro
  • 编辑功能:使用gemini-3-pro或flux.2-pro(两者均支持图片编辑)
  • 成本:仅需生成时使用flux.2-flex

Common Usage Patterns

常见使用模式

Basic generation

基础生成

bash
python scripts/generate_image.py "Your prompt here"
bash
python scripts/generate_image.py "Your prompt here"

Specify model

指定模型

bash
python scripts/generate_image.py "A cat in space" --model "black-forest-labs/flux.2-pro"
bash
python scripts/generate_image.py "A cat in space" --model "black-forest-labs/flux.2-pro"

Custom output path

自定义输出路径

bash
python scripts/generate_image.py "Abstract art" --output artwork.png
bash
python scripts/generate_image.py "Abstract art" --output artwork.png

Edit an existing image

编辑现有图片

bash
python scripts/generate_image.py "Make the background blue" --input photo.jpg
bash
python scripts/generate_image.py "Make the background blue" --input photo.jpg

Edit with a specific model

使用指定模型编辑

bash
python scripts/generate_image.py "Add sunglasses to the person" --input portrait.png --model "black-forest-labs/flux.2-pro"
bash
python scripts/generate_image.py "Add sunglasses to the person" --input portrait.png --model "black-forest-labs/flux.2-pro"

Edit with custom output

编辑并自定义输出

bash
python scripts/generate_image.py "Remove the text from the image" --input screenshot.png --output cleaned.png
bash
python scripts/generate_image.py "Remove the text from the image" --input screenshot.png --output cleaned.png

Multiple images

生成多张图片

Run the script multiple times with different prompts or output paths:
bash
python scripts/generate_image.py "Image 1 description" --output image1.png
python scripts/generate_image.py "Image 2 description" --output image2.png
多次运行脚本,使用不同的提示词或输出路径:
bash
python scripts/generate_image.py "Image 1 description" --output image1.png
python scripts/generate_image.py "Image 2 description" --output image2.png

Script Parameters

脚本参数

  • prompt
    (required): Text description of the image to generate, or editing instructions
  • --input
    or
    -i
    : Input image path for editing (enables edit mode)
  • --model
    or
    -m
    : OpenRouter model ID (default: google/gemini-3-pro-image-preview)
  • --output
    or
    -o
    : Output file path (default: generated_image.png)
  • --api-key
    : OpenRouter API key (overrides .env file)
  • prompt
    (必填):要生成的图片的文字描述,或编辑指令
  • --input
    -i
    :用于编辑的输入图片路径(启用编辑模式)
  • --model
    -m
    :OpenRouter模型ID(默认值:google/gemini-3-pro-image-preview)
  • --output
    -o
    :输出文件路径(默认值:generated_image.png)
  • --api-key
    :OpenRouter API密钥(覆盖.env文件中的配置)

Example Use Cases

示例用例

For Scientific Documents

用于科学文档

bash
undefined
bash
undefined

Generate a conceptual illustration for a paper

Generate a conceptual illustration for a paper

python scripts/generate_image.py "Microscopic view of cancer cells being attacked by immunotherapy agents, scientific illustration style" --output figures/immunotherapy_concept.png
python scripts/generate_image.py "Microscopic view of cancer cells being attacked by immunotherapy agents, scientific illustration style" --output figures/immunotherapy_concept.png

Create a visual for a presentation

Create a visual for a presentation

python scripts/generate_image.py "DNA double helix structure with highlighted mutation site, modern scientific visualization" --output slides/dna_mutation.png
undefined
python scripts/generate_image.py "DNA double helix structure with highlighted mutation site, modern scientific visualization" --output slides/dna_mutation.png
undefined

For Presentations and Posters

用于演示文稿和海报

bash
undefined
bash
undefined

Title slide background

Title slide background

python scripts/generate_image.py "Abstract blue and white background with subtle molecular patterns, professional presentation style" --output slides/background.png
python scripts/generate_image.py "Abstract blue and white background with subtle molecular patterns, professional presentation style" --output slides/background.png

Poster hero image

Poster hero image

python scripts/generate_image.py "Laboratory setting with modern equipment, photorealistic, well-lit" --output poster/hero.png
undefined
python scripts/generate_image.py "Laboratory setting with modern equipment, photorealistic, well-lit" --output poster/hero.png
undefined

For General Visual Content

用于通用视觉内容

bash
undefined
bash
undefined

Website or documentation images

Website or documentation images

python scripts/generate_image.py "Professional team collaboration around a digital whiteboard, modern office" --output docs/team_collaboration.png
python scripts/generate_image.py "Professional team collaboration around a digital whiteboard, modern office" --output docs/team_collaboration.png

Marketing materials

Marketing materials

python scripts/generate_image.py "Futuristic AI brain concept with glowing neural networks" --output marketing/ai_concept.png
undefined
python scripts/generate_image.py "Futuristic AI brain concept with glowing neural networks" --output marketing/ai_concept.png
undefined

Error Handling

错误处理

The script provides clear error messages for:
  • Missing API key (with setup instructions)
  • API errors (with status codes)
  • Unexpected response formats
  • Missing dependencies (requests library)
If the script fails, read the error message and address the issue before retrying.
脚本会针对以下情况提供清晰的错误提示:
  • 缺少API密钥(附带设置说明)
  • API错误(附带状态码)
  • 意外的响应格式
  • 缺少依赖项(requests库)
如果脚本运行失败,请阅读错误信息并解决问题后重试。

Notes

注意事项

  • Images are returned as base64-encoded data URLs and automatically saved as PNG files
  • The script supports both
    images
    and
    content
    response formats from different OpenRouter models
  • Generation time varies by model (typically 5-30 seconds)
  • For image editing, the input image is encoded as base64 and sent to the model
  • Supported input image formats: PNG, JPEG, GIF, WebP
  • Check OpenRouter pricing for cost information: https://openrouter.ai/models
  • 图片以base64编码的数据URL形式返回,并自动保存为PNG文件
  • 脚本支持不同OpenRouter模型返回的
    images
    content
    两种响应格式
  • 生成时间因模型而异(通常为5-30秒)
  • 图片编辑时,输入图片会被编码为base64并发送给模型
  • 支持的输入图片格式:PNG、JPEG、GIF、WebP
  • 查看OpenRouter定价信息:https://openrouter.ai/models

Image Editing Tips

图片编辑技巧

  • Be specific about what changes you want (e.g., "change the sky to sunset colors" vs "edit the sky")
  • Reference specific elements in the image when possible
  • For best results, use clear and detailed editing instructions
  • Both Gemini 3 Pro and FLUX.2 Pro support image editing through OpenRouter
  • 明确说明你想要的修改(例如:"将天空改为日落色彩" 而非 "编辑天空")
  • 尽可能引用图片中的特定元素
  • 为获得最佳效果,请使用清晰、详细的编辑指令
  • Gemini 3 Pro和FLUX.2 Pro均通过OpenRouter支持图片编辑

Integration with Other Skills

与其他技能的集成

  • scientific-schematics: Use for technical diagrams, flowcharts, circuits, pathways
  • generate-image: Use for photos, illustrations, artwork, visual concepts
  • scientific-slides: Combine with generate-image for visually rich presentations
  • latex-posters: Use generate-image for poster visuals and hero images
  • scientific-schematics:用于技术图表、流程图、电路图、通路图
  • generate-image:用于照片、插画、艺术品、视觉概念
  • scientific-slides:与generate-image结合使用,打造视觉丰富的演示文稿
  • latex-posters:使用generate-image制作海报视觉元素和主图