generate-image

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

generate-image - AI Image Generation

generate-image - AI图像生成

Uses Google Gemini (gemini-3-pro-image-preview) to generate images from text prompts.
借助Google Gemini(gemini-3-pro-image-preview),通过文本提示词生成图像。

Synopsis

语法

bash
codev generate-image "<prompt>" [options]
bash
codev generate-image "<prompt>" [options]

Options

选项

bash
-o, --output <file>        # Output file path (default: output.png)
-r, --resolution <res>     # Resolution: 1K, 2K, 4K (default: 1K)
-a, --aspect <ratio>       # Aspect ratio (default: 1:1)
--ref <image>              # Reference image (repeatable, max 14)
bash
-o, --output <file>        # 输出文件路径(默认值:output.png)
-r, --resolution <res>     # 分辨率:1K、2K、4K(默认值:1K)
-a, --aspect <ratio>       # 宽高比(默认值:1:1)
--ref <image>              # 参考图像(可重复使用,最多14张)

Aspect Ratios

支持的宽高比

1:1
|
16:9
|
9:16
|
3:4
|
4:3
|
3:2
|
2:3
1:1
|
16:9
|
9:16
|
3:4
|
4:3
|
3:2
|
2:3

Examples

示例

bash
undefined
bash
undefined

Basic generation

基础生成

codev generate-image "A sunset over mountains"
codev generate-image "A sunset over mountains"

High-res widescreen

高分辨率宽屏图像

codev generate-image "A futuristic city" -r 4K -a 16:9 -o city.png
codev generate-image "A futuristic city" -r 4K -a 16:9 -o city.png

With reference images (style transfer)

结合参考图像(风格迁移)

codev generate-image "Same style but with cats" --ref style.png --ref layout.png
codev generate-image "Same style but with cats" --ref style.png --ref layout.png

Prompt from file

从文件读取提示词

codev generate-image prompt.txt -o result.png
undefined
codev generate-image prompt.txt -o result.png
undefined

Prerequisites

前置条件

Requires
GEMINI_API_KEY
or
GOOGLE_API_KEY
environment variable. Get a key at https://aistudio.google.com/apikey
需要设置
GEMINI_API_KEY
GOOGLE_API_KEY
环境变量。可在https://aistudio.google.com/apikey获取密钥。

Common Mistakes

常见错误

  • Prompt must be quoted if it contains spaces
  • Prompt can also be a
    .txt
    file path (auto-detected by extension)
  • Reference images must exist on disk — max 14 images
  • Output defaults to
    output.png
    in current directory — use
    -o
    to change
  • 若提示词包含空格,必须用引号包裹
  • 提示词也可以是
    .txt
    文件路径(通过扩展名自动识别)
  • 参考图像必须存在于本地磁盘中——最多支持14张
  • 输出文件默认保存在当前目录的
    output.png
    ——使用
    -o
    选项可修改路径