adachsoft / ai-image-leonardo
Leonardo.ai image generation adapter for the AdachSoft AI image contract.
Requires
- php: ^8.3
- adachsoft/ai-image-contract: ^0.2
- adachsoft/collection: ^3.0
- guzzlehttp/guzzle: ^7.10
Requires (Dev)
- adachsoft/php-code-style: ^0.7.1
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^13.3
- rector/rector: ^2.6
- symplify/phpstan-rules: ^14.13
- vlucas/phpdotenv: ^5.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-09-09 02:03:54 UTC
README
Leonardo.ai image generation adapter for the AdachSoft AI image contract.
Requirements
- PHP 8.3 or newer
- A Leonardo.ai API key
Installation
composer require adachsoft/ai-image-leonardo
Configuration
Set the LEONARDO_API_KEY environment variable. When using the included CLI example, the value can be stored in a .env file in the project root:
LEONARDO_API_KEY=your-leonardo-api-key
Usage
The package exposes a generator factory compatible with the AdachSoft AI image contract:
<?php
declare(strict_types=1);
use AdachSoft\AiImageContract\Collections\ImageInputCollection;
use AdachSoft\AiImageContract\Models\GenerationRequest;
use AdachSoft\AiImageContract\ValueObjects\ImageSize;
use AdachSoft\AiImageContract\ValueObjects\Prompt;
use AdachSoft\AiImageLeonardo\Factory\LeonardoImageGeneratorFactory;
$generator = LeonardoImageGeneratorFactory::create(
apiKey: $_ENV['LEONARDO_API_KEY'],
);
$request = new GenerationRequest(
prompt: new Prompt('A small orange robot in pixel art style'),
imageInputs: new ImageInputCollection(),
size: new ImageSize(1024, 1024),
);
$response = $generator->generate($request);
$image = $response->images->first();
if ($image !== null && $image->url !== null) {
echo $image->url;
}
The generator submits an image generation job, polls Leonardo.ai until the job completes or times out, and maps the provider response to the shared contract.
Command-line example
The repository includes a command-line example that generates and downloads the first returned image:
php bin/generate_image.php "A small orange robot in pixel art style"
The image is saved to var/tmp.
Development
Install development dependencies and run the test suite:
composer install
composer test
Run static analysis and code style checks:
composer stan
composer cs:check
License
This package is released under the MIT License.