PHP code example of krisciunaskarolis / openai-images-generator

1. Go to this page and download the library: Download krisciunaskarolis/openai-images-generator 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/ */

    

krisciunaskarolis / openai-images-generator example snippets


use Krisciunas\OpenAi\Api\GenerateImageCommand;
use Krisciunas\OpenAi\Api\ImagePrompt;

$authorizationToken = 'YOUR-OPENAI-API-KEY';
$imagesGenerationCommand = new GenerateImageCommand();

$imagesData = $imagesGenerationCommand->execute(
    $authorizationToken,
    new ImagePrompt(
        'small kitty playing with red fish', //A text description of the desired images. The maximum length is 1000 characters.
        4, //Number of images to generate. Must be between 1 and 10
        ImagePrompt::SIZE_256x256, // The size of generated images
        ImagePrompt::FORMAT_URL //The format in which images are returned
    ),
);

$imagesPersistor = new ImagesPersist('/PATH/TO/IMAGES/DIRECTORY/');
$imagesPersistor->persist($imagesData, 'FILENAME_FORMAT_%s.png');

\Krisciunas\OpenAi\Api\ImagePrompt::FORMAT_URL;
\Krisciunas\OpenAi\Api\ImagePrompt::FORMAT_BASE_64;

\Krisciunas\OpenAi\Api\ImagePrompt::SIZE_256x256;
\Krisciunas\OpenAi\Api\ImagePrompt::SIZE_512x512;
\Krisciunas\OpenAi\Api\ImagePrompt::SIZE_1024x1024;