1. Go to this page and download the library: Download krecit/gemini-image-core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
krecit / gemini-image-core example snippets
recIT\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"
);
recIT\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"
);