Skip to content

Pass through provider specific Gemini image aspect ratios#282

Open
morcken wants to merge 1 commit intolaravel:0.xfrom
morcken:fix-gemini-image-aspect-ratio
Open

Pass through provider specific Gemini image aspect ratios#282
morcken wants to merge 1 commit intolaravel:0.xfrom
morcken:fix-gemini-image-aspect-ratio

Conversation

@morcken
Copy link

@morcken morcken commented Mar 18, 2026

Gemini supports image aspect ratios such as 3:4, but the SDK currently drops any ratio outside 1:1, 2:3, and 3:2 when building Gemini image options.

This PR makes Gemini consistent with the existing size(string $size) API by passing through non-null size values as aspect_ratio, while preserving the existing mappings for 1:1, 2:3, and 3:2.

Reproduction

use Laravel\Ai\Enums\Lab;
use Laravel\Ai\Files;
use Laravel\Ai\Image;

return Image::of($prompt)
    ->quality('medium')
    ->size('3:4')
    ->timeout(60)
    ->generate(provider: Lab::Gemini);

Before

  • GeminiProvider::defaultImageOptions() converted unknown aspect ratios to null, so size('3:4') was not forwarded to Gemini.

After

  • Non-null size values are passed through to Gemini as aspect_ratio.

Why this change

Tests

Added a focused unit test that verifies:

  • Gemini preserves 3:4 as aspect_ratio
  • An existing mapped ratio (1:1) still behaves as before

Backward Compatibility

This change is backward compatible:

  • No method signatures changed
  • square(), portrait(), and landscape() are unchanged
  • Existing known Gemini mappings are unchanged

@morcken morcken marked this pull request as ready for review March 18, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant