krecit / gemini-image-core
A standalone PHP client for Google Gemini Vision and Imagen 4. Generate high-quality images from text or image references seamlessly.
v1.0.0
2026-06-01 16:10 UTC
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.0
README
馃實 Read this in English | 馃嚜馃嚫 Leer en Espa帽ol
馃實 English
A standalone PHP client for Google Gemini Vision and Imagen 4. Generate high-quality images from text or image references seamlessly.
Installation
composer require krecit/gemini-image-core
Basic Usage
<?php require 'vendor/autoload.php'; use KrecIT\GeminiImageCore\GeminiImageClient; // Instantiate the client with your Google API Key $client = new GeminiImageClient('YOUR_API_KEY'); // 1. Generate an image from text (Uses Imagen 4) // Returns raw binary string $rawBinary = $client->generateImage("A futuristic city at night", "16:9"); // Save the image file_put_contents('city.jpg', $rawBinary); // 2. Generate an image with references (Uses Gemini 2.5 Flash Image) $base64References = [ base64_encode(file_get_contents('product.webp')) ]; $rawBinaryWithRef = $client->generateImageWithReferences( "Put this product on a luxury wooden table", $base64References, "1:1" );
Exception Handling
The package throws KrecIT\GeminiImageCore\Exceptions\GeminiException if generation fails or the API rejects the request.
use KrecIT\GeminiImageCore\Exceptions\GeminiException; try { $client->generateImage("..."); } catch (GeminiException $e) { echo "Error: " . $e->getMessage(); }
馃嚜馃嚫 Espa帽ol
Un cliente PHP independiente para Google Gemini Vision e Imagen 4. Genera im谩genes de alta calidad a partir de texto o referencias visuales sin complicaciones.
Instalaci贸n
composer require krecit/gemini-image-core
Uso B谩sico
<?php require 'vendor/autoload.php'; use KrecIT\GeminiImageCore\GeminiImageClient; // Instancia el cliente con tu API Key de Google $client = new GeminiImageClient('TU_API_KEY'); // 1. Generar una imagen desde cero (Usa Imagen 4) // Devuelve un string binario crudo $rawBinary = $client->generateImage("Una ciudad futurista de noche", "16:9"); // Guardar la imagen file_put_contents('ciudad.jpg', $rawBinary); // 2. Generar una imagen con referencias (Usa Gemini 2.5 Flash Image) $base64References = [ base64_encode(file_get_contents('producto.webp')) ]; $rawBinaryWithRef = $client->generateImageWithReferences( "Pon este producto en una mesa de madera lujosa", $base64References, "1:1" );
Manejo de Excepciones
El paquete lanza la excepci贸n KrecIT\GeminiImageCore\Exceptions\GeminiException si la generaci贸n falla o la API rechaza la solicitud.
use KrecIT\GeminiImageCore\Exceptions\GeminiException; try { $client->generateImage("..."); } catch (GeminiException $e) { echo "Error: " . $e->getMessage(); }