Single-shot Image Generation
Create high-quality images from text prompts
Single-shot generation is the simplest way to create images with Gemini. Provide a text description, and the model generates a complete image in one step. Perfect for quick iterations and prototyping.
Basic Example
Here's how to generate your first image with a simple text prompt:
Python
from google import genai
from PIL import Image
client = genai.Client()
prompt = "A photorealistic sunset over mountains with a lake reflection"
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=[prompt],
)
for part in response.parts:
if part.text is not None:
print(part.text)
elif part.inline_data is not None:
image = part.as_image()
image.save("generated_image.png")Configuration Options
Controlling Aspect Ratio
You can specify the aspect ratio of the generated image to match your needs:
Python - With Aspect Ratio
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=["A scenic landscape photo"],
config=types.GenerateContentConfig(
image_config=types.ImageConfig(
aspect_ratio="16:9" # Options: 1:1, 16:9, 9:16, 4:3, etc.
)
)
)
for part in response.parts:
if image := part.as_image():
image.save("landscape.png")1:116:99:164:33:4Best Practices
Be Descriptive
Provide clear, detailed descriptions instead of just keywords. The model understands natural language better than keyword lists.
Specify Style
Include style references like 'photorealistic', 'illustration', 'watercolor' to guide the visual output.
Mention Details
Include lighting, mood, composition details to get more precise results.