Generate images using the Imagen 4 model with simple text prompts:
from google import genaifrom google.genai import typesclient = genai.Client(vertexai=True, project=PROJECT_ID, location=LOCATION)prompt = """A white wall with two Art Deco travel posters mounted. First poster has the text: "NEPTUNE", tagline: "The jewel of the solar system!" Second poster has the text: "JUPITER", tagline: "Travel with the giants!""""image = client.models.generate_images( model="imagen-4.0-generate-001", prompt=prompt, config=types.GenerateImagesConfig( aspect_ratio="16:9", number_of_images=1, image_size="2K", safety_filter_level="BLOCK_MEDIUM_AND_ABOVE", person_generation="ALLOW_ADULT", ),)# Display the generated imagedisplay_image(image.generated_images[0].image)
Best for: High-quality images with natural lighting and photorealism
image = client.models.generate_images( model="imagen-4.0-generate-001", prompt="New York skyline at sunset", config=types.GenerateImagesConfig( number_of_images=1, aspect_ratio="3:4", image_size="2K", ),)
Best for: Brighter images with higher contrast and faster generation
image = client.models.generate_images( model="imagen-4.0-fast-generate-001", prompt="New York skyline at sunset", config=types.GenerateImagesConfig( number_of_images=1, aspect_ratio="3:4", image_size="2K", ),)
Best for: Exceptional quality with maximum photorealism
prompt = """Photorealistic night scene: looking into a brightly lit, classic 1960s American diner from the cold street outside. The entire view is filtered through a large pane of glass streaked with rainwater."""image = client.models.generate_images( model="imagen-4.0-ultra-generate-001", prompt=prompt, config=types.GenerateImagesConfig( aspect_ratio="1:1", image_size="2K", ),)
prompt = """Una pintura al óleo impresionista de una taza de café sobre una mesa en una cocina, con las palabras 'buenos días' escritas en una fuente caprichosa en la taza."""image = client.models.generate_images( model="imagen-4.0-generate-001", prompt=prompt, config=types.GenerateImagesConfig( aspect_ratio="1:1", enhance_prompt=True, # Enhance the prompt ),)
Supported languages: English, Spanish, French, German, Portuguese, Chinese (Simplified/Traditional), Japanese, Korean, and Hindi.
Enable automatic prompt enhancement to generate more detailed descriptions:
image = client.models.generate_images( model="imagen-4.0-generate-001", prompt="a coffee cup on a kitchen table", config=types.GenerateImagesConfig( enhance_prompt=True, # AI will enhance your prompt ),)# View the enhanced promptprint(image.generated_images[0].enhanced_prompt)
prompt = """A panel of a comic strip. A cute gray cat is talking to a bulldog. The cat says in a talk bubble: "You really seem to enjoy going outside. Fascinating." Well-articulated illustration with confident lines and shading."""image = client.models.generate_images( model="imagen-4.0-generate-001", prompt=prompt, config=types.GenerateImagesConfig( aspect_ratio="4:3", image_size="2K", ),)
Generate tutorials or guides with mixed text and images:
prompt = """Create a tutorial explaining how to make a peanut butter and jelly sandwich in three easy steps. For each step, provide a title with the number of the step, an explanation, and also generate an image to illustrate the content."""response = client.models.generate_content( model=MODEL_ID, contents=prompt, config=GenerateContentConfig( response_modalities=["TEXT", "IMAGE"], # Both modalities image_config=ImageConfig( aspect_ratio="4:3", ), ),)# Display interleaved contentfor part in response.candidates[0].content.parts: if part.text: display(Markdown(part.text)) if part.inline_data: display(Image(data=part.inline_data.data))
This feature is perfect for creating recipes, how-to guides, product documentation, and educational content.
prompt = """Portrait of a woman, 85mm lens, f/1.4 aperture, shallow depth of field,natural window lighting, golden hour, professional studio quality"""
For text rendering, be explicit about placement and style:
prompt = """A vintage travel poster with the text 'VISIT MARS' in bold Art Deco lettering at the top, and the tagline 'The Red Planet Awaits' in elegant script at the bottom"""
Control whether people appear in generated images:
config=types.GenerateImagesConfig( person_generation="DONT_ALLOW", # No people # person_generation="ALLOW_ADULT", # Adults only # person_generation="ALLOW_ALL", # All ages)
Here’s a complete example generating a high-quality image:
from google import genaifrom google.genai import typesimport IPython.display# Initialize clientPROJECT_ID = "your-project-id"LOCATION = "us-central1"client = genai.Client(vertexai=True, project=PROJECT_ID, location=LOCATION)# Generate imageprompt = """Design an elegant movie poster for 'The Crimson Thread'. A close-up shot of two hands almost touching, with a vibrant crimson thread winding between their fingers. The title 'The Crimson Thread' should appear in flowy hand-stitched embroidery style. Soft-focus garden background."""image = client.models.generate_images( model="imagen-4.0-generate-001", prompt=prompt, config=types.GenerateImagesConfig( aspect_ratio="1:1", image_size="2K", number_of_images=1, safety_filter_level="BLOCK_MEDIUM_AND_ABOVE", person_generation="ALLOW_ADULT", add_watermark=True, ),)# Display resultIPython.display.display(image.generated_images[0].image._pil_image)