文本生成图片
AI-generatedSummary
Generates images from text prompts using Google's Gemini 3.x or 2.5 Flash models, with options for aspect ratio, resolution, and output format.
Inputs
- model (required) — The Gemini model to use for generation (e.g., gemini-3.1-flash-image-preview, gemini-2.5-flash-image).
- prompt (required) — The text prompt describing the desired image.
- aspectRatio — The aspect ratio of the output image (e.g., 1:1, 16:9, 9:16).
- resolution — The image resolution (e.g., 512px, 1K, 2K, 4K). Only available for certain high-res models.
- outputFormat — Format of the output data (binary, url, dataUrl, or base64).
- throwOnFailure — If true, throws an error on generation failure; if false, returns success:false with details.
Output shape
A JSON object with a success flag and a count of generated images. Includes a binary property (if format is binary) or a text string/array property (for other formats).
For binary output, image count determines property names (e.g., data, data_1). If showRawResponse is true, the original API response is included.
Examples
Example 1: Generate a square image from a text prompt in binary format.
Set model to 'gemini-3.1-flash-image-preview', aspect ratio to '1:1', output format to 'binary'.
Example 2: Generate a landscape image and get the URL.
Set model to 'gemini-2.5-flash-image', aspect ratio to '16:9', output format to 'url'.