SuperAPI AI 工具集

openai-image-gen

设计与创作

查看项目

更新于 10-16 09:21

技能介绍

OpenAI Image Gen 是一个用于批量生成图片的命令行脚本工具,通过 OpenAI Images API 渲染图片。它的核心特点是:自动生成一批“随机但结构化”的提示词,然后调用 OpenAI 图像模型批量出图,并附带一个 index.html 缩略图画廊用于浏览结果。

用途 该工具适合需要一次性生成多张图片、并希望快速浏览结果的场景。它既支持使用自定义提示词,也支持由脚本采样生成随机提示词。

主要能力

  • 批量生成:通过 --count 指定生成数量。
  • 多模型支持:支持 GPT image 系列模型(gpt-image-1、gpt-image-1-mini、gpt-image-1.5)、DALL-E 3 和 DALL-E 2。
  • 自动默认参数:脚本会根据所选模型自动选择合适的默认参数。
  • 输出产物:生成图片文件(.png、.jpeg 或 *.webp,取决于模型与 --output-format)、prompts.json(提示词到文件的映射)以及 index.html(缩略图画廊)。

使用方式 基本运行命令: python3 {baseDir}/scripts/gen.py open ~/Projects/tmp/openai-image-gen-*/index.html # 如果 ~/Projects/tmp 存在;否则 ./tmp/...

常用参数示例:

使用 GPT image 模型及各种选项

python3 {baseDir}/scripts/gen.py --count 16 --model gpt-image-1 python3 {baseDir}/scripts/gen.py --prompt "ultra-detailed studio photo of a lobster astronaut" --count 4 python3 {baseDir}/scripts/gen.py --size 1536x1024 --quality high --out-dir ./out/images python3 {baseDir}/scripts/gen.py --model gpt-image-1.5 --background transparent --output-format webp

DALL-E 3(注意:count 会自动限制为 1)

python3 {baseDir}/scripts/gen.py --model dall-e-3 --quality hd --size 1792x1024 --style vivid python3 {baseDir}/scripts/gen.py --model dall-e-3 --style natural --prompt "serene mountain landscape"

DALL-E 2

python3 {baseDir}/scripts/gen.py --model dall-e-2 --size 512x512 --count 4

模型特定参数 不同模型支持不同的参数取值,脚本会根据模型自动选择适当的默认值。

尺寸(Size)

  • GPT image 模型(gpt-image-1、gpt-image-1-mini、gpt-image-1.5):1024x1024、1536x1024(横向)、1024x1536(纵向)或 auto;默认 1024x1024。
  • dall-e-3:1024x1024、1792x1024 或 1024x1792;默认 1024x1024。
  • dall-e-2:256x256、512x512 或 1024x1024;默认 1024x1024。

质量(Quality)

  • GPT image 模型:auto、high、medium 或 low;默认 high。
  • dall-e-3:hd 或 standard;默认 standard。
  • dall-e-2:仅 standard;默认 standard。

其他显著差异

  • dall-e-3 一次只支持生成 1 张图片(n=1)。使用该模型时,脚本会自动将 count 限制为 1。
  • GPT image 模型支持额外参数:
    • --background:transparent、opaque 或 auto(默认)。
    • --output-format:png(默认)、jpeg 或 webp。
    • 注意:stream 和 moderation 可通过 API 使用,但本脚本尚未实现。
  • dall-e-3 具有 --style 参数:vivid(超写实、戏剧化)或 natural(更自然的外观)。

输出

  • .png、.jpeg 或 *.webp 图片(输出格式取决于模型与 --output-format)。
  • prompts.json(提示词到文件的映射)。
  • index.html(缩略图画廊)。

适用场景 适合需要批量生成图片并集中查看结果的用户,例如快速产出多张概念图、测试不同提示词或参数组合、以及通过画廊浏览生成效果。

限制

  • 使用 DALL-E 3 时,生成数量会被自动限制为 1。
  • stream 和 moderation 参数虽可通过 API 使用,但本脚本尚未实现。
  • 关于收费、价格、平台支持范围等信息,资料中暂未提供。