Skip to content

Commit 2fe0256

Browse files
committed
docs(gemini): Update image generation docs
1 parent c677222 commit 2fe0256

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

docs/core-concepts/image-generation.md

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,77 @@ if ($image->hasBase64()) {
158158
}
159159
```
160160

161+
#### Image Editing
162+
163+
OpenAI's `gpt-image-1` model supports editing existing images. Pass your images as the second parameter to `withPrompt()`:
164+
165+
```php
166+
use Prism\Prism\ValueObjects\Media\Image;
167+
168+
$originalImage = Image::fromLocalPath('photos/landscape.png');
169+
170+
$response = Prism::image()
171+
->using('openai', 'gpt-image-1')
172+
->withPrompt('Add a vaporwave sunset to the background', [$originalImage])
173+
->withProviderOptions([
174+
'size' => '1024x1024',
175+
'output_format' => 'png',
176+
'quality' => 'high',
177+
])
178+
->generate();
179+
180+
// The edited image is returned as base64
181+
$editedImage = $response->firstImage();
182+
file_put_contents('edited-landscape.png', base64_decode($editedImage->base64));
183+
```
184+
185+
You can edit multiple images at once:
186+
187+
```php
188+
$response = Prism::image()
189+
->using('openai', 'gpt-image-1')
190+
->withPrompt('Make the colors more vibrant', [
191+
Image::fromLocalPath('photo1.png'),
192+
Image::fromLocalPath('photo2.png')->as('custom-name.png'),
193+
])
194+
->generate();
195+
```
196+
197+
For precise edits, use a mask to specify which areas to modify:
198+
199+
```php
200+
$response = Prism::image()
201+
->using('openai', 'gpt-image-1')
202+
->withPrompt('Replace the sky with a starry night', [
203+
Image::fromLocalPath('landscape.png'),
204+
])
205+
->withProviderOptions([
206+
'mask' => Image::fromLocalPath('sky-mask.png'), // White areas will be edited
207+
'size' => '1024x1024',
208+
'output_format' => 'png',
209+
])
210+
->generate();
211+
```
212+
213+
> [!NOTE]
214+
> The mask should be a PNG image where white pixels indicate areas to edit and transparent pixels indicate areas to preserve.
215+
161216
### Gemini Options
162217

163218
Gemini offers customizations, depending on what model is selected. All Gemini image generation models return base64-encoded images only. They also return `mimeType`.
164219

165220
### Gemini Flash Preview Image Generation
166221

167-
Gemini conversational image generation provides the option to edit images:
222+
Gemini conversational image generation provides the option to edit images by passing them as the second parameter to `withPrompt()`:
168223

169224
```php
170-
$originalImage = fopen('image/boots.png', 'r');
225+
use Prism\Prism\ValueObjects\Media\Image;
226+
227+
$originalImage = Image::fromLocalPath('image/boots.png');
171228

172229
$response = Prism::image()
173230
->using(Provider::Gemini, 'gemini-2.0-flash-preview-image-generation')
174-
->withPrompt('Actually, could we make those boots red?')
175-
->withProviderOptions([
176-
'image' => $originalImage,
177-
'image_mime_type' => 'image/png',
178-
])
231+
->withPrompt('Actually, could we make those boots red?', [$originalImage])
179232
->generate();
180233
```
181234

0 commit comments

Comments
 (0)