From d9a81f0afc7e1aceb2b5268f59e46f31894090a4 Mon Sep 17 00:00:00 2001 From: Marcello Duarte Date: Fri, 31 Jul 2026 18:22:28 +0100 Subject: [PATCH] Stop telling people the generated image is a PNG Verified against the live API: the Gemini image models return image/jpeg by default, but every example wrote the bytes to a .png file. The MIME type comes back on each image, so the examples now take the extension from the response instead of assuming. --- README.md | 14 +++++++++----- docs/provider.md | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 68c368c..e375cfc 100644 --- a/README.md +++ b/README.md @@ -91,13 +91,17 @@ $result = $provider->generateImage( ] ); -$imageData = base64_decode($result['images'][0]['data']); -file_put_contents('output.png', $imageData); +$image = $result['images'][0]; -// Or save straight to disk +// These models return JPEG by default, so take the extension from the response +// rather than assuming PNG. +$extension = str_replace('image/', '', $image['mimeType']); +file_put_contents("output.{$extension}", base64_decode($image['data'])); + +// Or save straight to disk, choosing your own path $provider->generateImageToFile( prompt: 'A modern minimalist workspace', - outputPath: '/path/to/image.png' + outputPath: '/path/to/image.jpg' ); ``` @@ -116,7 +120,7 @@ $result = $provider->editImage( prompt: 'Make the sky dramatic and overcast', ); -file_put_contents('edited.png', base64_decode($result['images'][0]['data'])); +file_put_contents('edited.jpg', base64_decode($result['images'][0]['data'])); echo $result['text']; // any commentary the model returned alongside the image ``` diff --git a/docs/provider.md b/docs/provider.md index 28cc550..75493de 100644 --- a/docs/provider.md +++ b/docs/provider.md @@ -76,13 +76,17 @@ $result = $provider->generateImage( ] ); -$imageData = base64_decode($result['images'][0]['data']); -file_put_contents('output.png', $imageData); +$image = $result['images'][0]; -// Or save directly to file +// These models return JPEG by default, so take the extension from the response +// rather than assuming PNG. +$extension = str_replace('image/', '', $image['mimeType']); +file_put_contents("output.{$extension}", base64_decode($image['data'])); + +// Or save directly to file, choosing your own path $provider->generateImageToFile( prompt: 'A modern minimalist workspace', - outputPath: '/path/to/image.png', + outputPath: '/path/to/image.jpg', ); ``` @@ -101,7 +105,7 @@ $result = $provider->editImage( prompt: 'Make the sky dramatic and overcast', ); -file_put_contents('edited.png', base64_decode($result['images'][0]['data'])); +file_put_contents('edited.jpg', base64_decode($result['images'][0]['data'])); echo $result['text']; ```