PHP code example of kdosiodjinud / ai-generate-image-by-reference

1. Go to this page and download the library: Download kdosiodjinud/ai-generate-image-by-reference 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/ */

    

kdosiodjinud / ai-generate-image-by-reference example snippets


use AiGenerateImageByReference\AiGenerateImageByReference;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$apiKey = 'sk-...';

$logger = new Logger('ai');
$logger->pushHandler(new StreamHandler('php://stdout'));

$ai = new AiGenerateImageByReference($apiKey, $logger);

$generatedImageBase64 = $ai
    ->setStyleImage('/path/to/reference-style.png') // reference image for style
    ->addContentImage('/path/to/content-image.png', 'Add glasses to the person') // content with description
    ->generate('A sunny outdoor scene with the person reading a book.');

if ($generatedImageBase64) {
    file_put_contents('output.png', base64_decode($generatedImageBase64));
}

use GuzzleHttp\Client;

$customClient = new Client([...]);
$ai = new AiGenerateImageByReference($apiKey, $logger, $customClient);



declare(strict_types=1);

namespace App\OpenAi\Tool;

use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$apiKey = 'sk-your-real-key';

$logger = new Logger('ai');
$logger->pushHandler(new StreamHandler('php://stdout'));

$ai = new AiGenerateImageByReference($apiKey, $logger);

$generatedImageBase64 = $ai
    ->setStyleImage('style.png')
    ->addContentImage('tyna.png', 'girl named Tina')
    ->addContentImage('fredy.png', 'boy named Fredy')
    ->generate('Fredy and Tina in a park on a sunny day with blue sky – Fredy is riding a bicycle');

if ($generatedImageBase64) {
    file_put_contents('output.png', base64_decode($generatedImageBase64));
}
bash
vendor/bin/php-cs-fixer fix
bash
> PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix
>