1 of 9

Generating Images With Google’s Imagen 3 APIs

Mar 2025

2 of 9

Evolution of AI-driven Image Generation

Image generation has improved drastically from the early days:

  1. GANs

  • Variational Auto Encoders

  • Diffusion models

3 of 9

Applications Are Numerous

Prompt: “Create an image using Imagen 3 as per this description: A collage of images, all of equal sizes, showcasing different use cases: a product design, an advertisement featuring a person, a videogame scene, a building architecture”

🡨 Image generated by Imagen 3

4 of 9

Imagen 3

  1. Imagen 3 is Google's latest and most advanced text-to-image diffusion model
  2. High levels of realism, accurate typography, enhanced understanding of prompts, fine-grained control over aesthetics and style, and safety

5 of 9

Prompting For Image Generation

Prompt (max 480 tokens): Generate a highly detailed, ultra-realistic portrait of a young woman with light olive skin and green eyes. She has well-defined, arched eyebrows, natural freckles across her cheeks and nose, and soft, full lips. Her brown hair is tied back loosely with a few strands framing her face. She wears minimal makeup, with a fresh and natural appearance. The lighting is soft and natural, casting subtle shadows that enhance the contours of her face. The background is blurred greenery, suggesting an outdoor setting. Photorealistic, cinematic style, 8K resolution, highly detailed skin texture, depth of field.

6 of 9

Code Walkthrough

7 of 9

Imagen 3 API Explanation

client = genai.Client(api_key='GEMINI_API_KEY’)

prompt_text = ‘Dogs chasing a cat on a beach’

config = types.GenerateImagesConfig(

number_of_images=2,

aspect_ratio='16:9',

safety_filter_level='BLOCK_MEDIUM_AND_ABOVE',

person_generation='DONT_ALLOW'

)

response = client.models.generate_images(

model='imagen-3.0-generate-002',

prompt=prompt_text,

config=config

)

Parameters Explanation:

  1. model: Specifies the version of the Imagen model to use. For Imagen 3, use 'imagen-3.0-generate-002'.
  2. prompt: A string describing the desired image content
  3. config: An instance of GenerateImagesConfig containing optional parameters to customize image generation:
    • number_of_images: Determines how many images to generate. Acceptable values range from 1 to 4, with the default being 4.
    • aspect_ratio: Sets the aspect ratio of the generated images. Supported values include: '1:1' (Square), '3:4' (Portrait fullscreen), '4:3' (Fullscreen), '9:16' (Portrait), '16:9' (Widescreen) The default is '1:1'.
    • safety_filter_level: Applies a safety filter to the generated images. Available options are:
      • 'BLOCK_LOW_AND_ABOVE': Blocks content with a safety score of LOW, MEDIUM, or HIGH. Most restrictive, as it blocks even LOW RISK images.
      • 'BLOCK_MEDIUM_AND_ABOVE': Blocks content with a safety score of MEDIUM or HIGH. This is the default value.
      • 'BLOCK_ONLY_HIGH': Blocks content with a safety score of HIGH.
      • 'BLOCK_NONE': Doesn’t block, use with caution
    • person_generation: Controls the generation of human figures in images. Options include:
      • 'DONT_ALLOW', 'ALLOW_ADULT','ALLOW_ALL': The default value is 'ALLOW_ADULT'. 

Rate limit: 20 Images Per Minute

8 of 9

Pricing

9 of 9

Reach Us Here