Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
```

Expand All @@ -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
```

Expand Down
14 changes: 9 additions & 5 deletions docs/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
```

Expand All @@ -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'];
```

Expand Down
Loading