Search by

adachsoft / ai-image-leonardo

Arkadiusz Adach

Leonardo.ai image generation adapter for the AdachSoft AI image contract.

Package info

gitlab.com/a.adach/ai-image-leonardo

Issues

pkg:composer/adachsoft/ai-image-leonardo

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-09-08 05:40 UTC

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.