adachsoft / ai-image-leonardo
Leonardo.ai image generation adapter for the AdachSoft AI image contract.
Requires
- php: ^8.3
- adachsoft/ai-image-contract: ^0.3
- 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-11-18 02:50:04 UTC
README
Leonardo.ai image generation adapter and Composer-discoverable plugin for the AdachSoft AI image contract ^0.3.
Requirements
- PHP 8.3 or newer
- A Leonardo.ai API key
Installation
composer require adachsoft/ai-image-leonardo
The package registers AdachSoft\\AiImageLeonardo\\Plugin\\LeonardoImageGeneratorPlugin under the Composer extra key adachsoft/ai-image-contract.plugins with the plugin ID adachsoft.ai-image-leonardo. The plugin has no required constructor arguments and accepts only the required api_key parameter.
Configuration
Set the LEONARDO_API_KEY environment variable. When using the included CLI example or E2E test, the value can also be stored in a .env file in the project root. Copy .env.example to .env and provide your key:
LEONARDO_API_KEY=your-leonardo-api-key
Usage
The package exposes the v0.3 contract DTOs and preserves direct factory configuration for existing consumers:
<?php
declare(strict_types=1);
use AdachSoft\AiImageContract\Collections\ImageInputVoCollection;
use AdachSoft\AiImageContract\Models\GenerationRequestDto;
use AdachSoft\AiImageContract\ValueObjects\ImageSizeVo;
use AdachSoft\AiImageContract\ValueObjects\PromptVo;
use AdachSoft\AiImageLeonardo\Factory\LeonardoImageGeneratorFactory;
$generator = LeonardoImageGeneratorFactory::create(
apiKey: $_ENV['LEONARDO_API_KEY'],
);
$request = new GenerationRequestDto(
prompt: new PromptVo('A small orange robot in pixel art style'),
imageInputs: new ImageInputVoCollection(),
size: new ImageSizeVo(1024, 1024),
);
$response = $generator->generate($request);
$image = $response->images->first();
if ($image !== null && $image->url !== null) {
echo $image->url;
}
Applications using the contract's plugin discovery can instantiate the registered plugin and supply its parameters through PluginParametersDto:
use AdachSoft\AiImageContract\Plugins\PluginParametersDto;
use AdachSoft\AiImageLeonardo\Plugin\LeonardoImageGeneratorPlugin;
$plugin = new LeonardoImageGeneratorPlugin();
$generator = $plugin->create(new PluginParametersDto([
'api_key' => $_ENV['LEONARDO_API_KEY'],
]));
The generator submits an image generation job, polls Leonardo.ai until the job completes or times out, and maps the response to ImageResponseDto with a GeneratedImageCollection of GeneratedImageDto objects.
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 streamed to var/tmp; network requests and downloaded data are subject to fixed internal time and size limits.
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.