Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/core/llms.txt

Use this file to discover all available pages before exploring further.

ImageResult is the value object returned after an image generation request completes. It exposes the first generated image directly through the output convenience property, the full set of generated images through images, and the standard token usage and provider metadata fields shared by all result types.

Properties

output
ImageData
required
The first generated image, provided as a convenience so single-image workflows do not need to index into the images array. This is always the same object as images[0].
images
array<int, ImageData>
All images generated in this request. When only one image was requested, this array contains a single element that is identical to output.
usage
Usage
required
Token consumption statistics for this request.
rawResponse
array<string, mixed>
The unmodified response payload returned by the provider’s API. Useful for debugging or accessing provider-specific fields not surfaced in the structured properties above.
providerMetadata
array<string, mixed>
Provider-specific metadata keyed by provider name. Contents vary across providers and may include safety ratings, seed values, or model-specific annotations.

Code examples

Saving a single image

$result = $ai->image('A photorealistic red panda in a bamboo forest, golden hour.');

// Save directly using the convenience property
$result->output->save('/var/www/storage/red-panda.png');

// Or decode to bytes for streaming in an HTTP response
header('Content-Type: ' . $result->output->mimeType);
echo $result->output->bytes();

Iterating multiple images

$result = $ai->image('Abstract watercolour swirl', n: 4);

foreach ($result->images as $index => $image) {
    $path = "/var/www/storage/swatch-{$index}.png";
    $image->save($path);
    echo "Saved image {$index} to {$path}";

    // Inspect dimensions when the provider reports them
    if ($image->width !== null && $image->height !== null) {
        echo " ({$image->width}×{$image->height})";
    }

    echo "\n";
}

echo "Total images: " . count($result->images) . "\n";
echo "Input tokens used: " . $result->usage->inputTokens . "\n";

Using a URL-based result

$result = $ai->image('Minimalist vector logo for a tech startup.');

$image = $result->output;

if ($image->url !== null) {
    // Provider returned a hosted URL — use it directly
    echo "Image URL: {$image->url}\n";
} elseif ($image->base64 !== null) {
    // Provider returned inline Base64 data
    $image->save('/tmp/logo.png');
}

Build docs developers (and LLMs) love