Skip to content

Images ​

Image::of() renders a prompt into pictures. OpenAI, Gemini, Azure, xAI, and Bedrock generate; OpenRouter routes to a hosted image model. Size and orientation travel with the request, reference images travel as attachments.

Generating ​

Shape the output with square(), portrait(), or landscape(), guide quality with quality('high'), bound the call with timeout():

php
use Crustum\Ai\Image;

$image = Image::of('A donut sitting on the kitchen counter.')->landscape()->generate();
echo count($image) . " image\n";
echo $image->firstImage()->mime() . PHP_EOL;
text
1 image
image/png

Reference images attach like message attachments (from a path, storage, upload, or URL), and the model restyles or extends them. Some providers return several images per request (OpenAI and Azure accept an n provider option); the response counts them, lists them in images, and firstImage() picks the headliner.

Storing ​

Generated bytes persist through the configured filesystem without leaving the fluent chain (store(), storeAs('image.jpg'), storePublicly(), storePubliclyAs()), or hand the response to toHtml() for an inline tag. Generation queues like everything else, with an ImageResponse in the then() callback.

See also ​

Released under the MIT License.