Source path: app/Services/Ai/Image/GeminiImage.php
Extracted from supplied specification. Review before copying into application.

<?php
namespace App\Services\Ai\Image;

use App\Services\Ai\ImageProvider;
use Illuminate\Support\Facades\Http;

class GeminiImage implements ImageProvider
{
    public function configured(array $c): bool { return !empty($c['api_key']) && !empty($c['model']); }

    public function generate(string $prompt, string $size, array $c): string
    {
        $res = Http::withHeaders(['x-goog-api-key' => $c['api_key']])->timeout(120)->post(
            "https://generativelanguage.googleapis.com/v1beta/models/{$c['model']}:generateContent",
            [
                'contents' => [['parts' => [['text' => $prompt]]]],
                'generationConfig' => ['responseModalities' => ['TEXT', 'IMAGE']],
            ]
        )->throw();

        foreach ($res->json('candidates.0.content.parts', []) as $part) {
            if (isset($part['inlineData']['data'])) return base64_decode($part['inlineData']['data']);
        }
        throw new \RuntimeException('Gemini returned no image (possibly blocked by safety filters).');
    }
}
