mcpField
G
generate-image

generate-image

github.com/leonchaox创意与媒体99071 次安装15 周前更新
代码仓库

关于 generate-image

Generate Image 是使用 OpenRouter 图像模型生成和编辑图片的技能,适用于插画、照片和演示文稿图形等通用视觉素材。它支持选择模型并指定输出路径。

主要功能

  1. 01根据文本提示生成图像
  2. 02通过输入文件编辑图像
  3. 03选择列出的 OpenRouter 模型
  4. 04设置自定义输出路径
  5. 05将生成图像保存为 PNG

适用场景

  1. 01为论文制作概念插画
  2. 02制作演示文稿背景
  3. 03对现有图像进行指定修改

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/leonchaox/qinyan-academic-skills --skill generate-image

安装后在 Claude Code 中输入/generate-image确认已加载。

附带文件scripts/generate_image.py

详细介绍

生成图像

使用 OpenRouter 的图像生成模型生成和编辑高质量图像,包括 FLUX.2 Pro 和 Gemini 3.1 Flash Image Preview。

何时使用此技能

以下情况使用 generate-image:

  • 照片和写实图像
  • 艺术插画和艺术作品
  • 概念艺术和视觉概念
  • 演示文稿或文档的视觉素材
  • 图像编辑和修改
  • 任何通用图像生成需求

以下情况改用 scientific-schematics:

  • 流程图和过程图
  • 电路图和电气原理图
  • 生物通路和信号级联
  • 系统架构图
  • CONSORT 流程图和方法流程图
  • 任何技术图或示意图

快速开始

使用 scripts/generate_image.py 脚本生成或编辑图像:

# Generate a new image
python scripts/generate_image.py "A beautiful sunset over mountains"

# Edit an existing image
python scripts/generate_image.py "Make the sky purple" --input photo.jpg

此脚本会生成或编辑图像,并将其保存为当前目录下的 generated_image.png。

API 密钥设置

重要: 此脚本需要 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 密钥,会提供明确的错误消息。

模型选择

默认模型: google/gemini-3.1-flash-image-preview(质量高,推荐)

可用于生成和编辑的模型:

  • google/gemini-3.1-flash-image-preview - 质量高,支持生成和编辑
  • black-forest-labs/flux.2-pro - 速度快、质量高,支持生成和编辑

仅用于生成:

  • black-forest-labs/flux.2-flex - 速度快、成本低,但质量不及 pro

根据以下情况选择:

  • 质量: 使用 gemini-3.1-flash-image-preview 或 flux.2-pro
  • 编辑: 使用 gemini-3.1-flash-image-preview 或 flux.2-pro(两者都支持图像编辑)
  • 成本: 仅生成图像时使用 flux.2-flex

常见用法

基本生成
python scripts/generate_image.py "Your prompt here"
指定模型
python scripts/generate_image.py "A cat in space" --model "black-forest-labs/flux.2-pro"
自定义输出路径
python scripts/generate_image.py "Abstract art" --output artwork.png
编辑现有图像
python scripts/generate_image.py "Make the background blue" --input photo.jpg
使用指定模型编辑
python scripts/generate_image.py "Add sunglasses to the person" --input portrait.png --model "black-forest-labs/flux.2-pro"
编辑并自定义输出路径
python scripts/generate_image.py "Remove the text from the image" --input screenshot.png --output cleaned.png
多张图像

使用不同的提示词或输出路径多次运行脚本:

python scripts/generate_image.py "Image 1 description" --output image1.png
python scripts/generate_image.py "Image 2 description" --output image2.png

脚本参数

  • prompt(必需):要生成的图像的文字描述,或编辑说明
  • --input 或 -i:用于编辑的输入图像路径(启用编辑模式)
  • --model 或 -m:OpenRouter 模型 ID(默认:google/gemini-3.1-flash-image-preview)
  • --output 或 -o:输出文件路径(默认:generated_image.png)
  • --api-key:OpenRouter API 密钥(覆盖 .env 文件中的设置)

使用场景示例

科学文档
# 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

# 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
演示文稿和海报
# Title slide background
python scripts/generate_image.py "Abstract blue and white background with subtle molecular patterns, professional presentation style" --output slides/background.png

# Poster hero image
python scripts/generate_image.py "Laboratory setting with modern equipment, photorealistic, well-lit" --output poster/hero.png
通用视觉内容
# Website or documentation images
python scripts/generate_image.py "Professional team collaboration around a digital whiteboard, modern office" --output docs/team_collaboration.png

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

错误处理

脚本会针对以下问题提供明确的错误消息:

  • 缺少 API 密钥(附带设置说明)
  • API 错误(附带状态码)
  • 意外的响应格式
  • 缺少依赖项(requests 库)

如果脚本运行失败,请先阅读错误消息并解决问题,再重试。

备注

  • 图像以 base64 编码的数据 URL 形式返回,并会自动保存为 PNG 文件
  • 脚本支持不同 OpenRouter 模型返回的 images 和 content 两种响应格式
  • 生成时间因模型而异(通常为 5-30 秒)
  • 编辑图像时,输入图像会先进行 base64 编码,再发送给模型
  • 支持的输入图像格式:PNG、JPEG、GIF、WebP
  • 如需了解费用信息,请查看 OpenRouter 定价:https://openrouter.ai/models

图像编辑技巧

  • 明确说明希望进行哪些更改(例如,“将天空改成日落色调”,而不是“编辑天空”)
  • 尽可能指出图像中的特定元素
  • 为获得最佳效果,请使用清晰、详细的编辑说明
  • Gemini 3.1 Flash Image Preview 和 FLUX.2 Pro 均支持通过 OpenRouter 编辑图像

与其他技能集成

  • scientific-schematics:用于技术图表、流程图、电路图、通路图
  • generate-image:用于照片、插画、艺术作品、视觉概念
  • scientific-slides:与 generate-image 配合,用于制作视觉效果丰富的演示文稿
  • latex-posters:使用 generate-image 创建海报视觉素材和主视觉图

评论

支持 Markdown