Skip to content

Support for aspect ratio control in image generation (gemini's nano-banana)Β #3119

@aldensiol

Description

@aldensiol

Description

Recently Gemini launched support for aspect ratio control during image generation.

Supported ratios include:

  • Landscape: 21:9, 16:9, 4:3, 3:2
  • Square: 1:1
  • Portrait: 9:16, 3:4, 2:3
  • Flexible: 5:4, 4:5
# code from google's documentation
response = client.models.generate_content(
    model="gemini-2.5-flash-image",
    contents=[prompt, image],
    config=types.GenerateContentConfig(
        response_modalities=["IMAGE"],
        image_config=types.ImageConfig(
            aspect_ratio="16:9",
        )
    )
)

Perhaps the BinaryImage object could be updated to support an aspect_ratio (Optional[str]) arg

from pydantic_ai import BinaryImage

# just an example
nano_banana_agent = Agent(
    output_type=BinaryImage(aspect_ratio="16:9",
    **kwargs,
)

response = await nano_banana_agent.run(user_prompt="Generate a cartoony image of halloween")
# return base64 image in the desired aspect ratio
return response.output.data_uri

References

Blog from google dev: https://developers.googleblog.com/en/gemini-2-5-flash-image-now-ready-for-production-with-new-aspect-ratios/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions