aimeos / prisma
A powerful PHP package for integrating media related Large Language Models (LLMs) into your applications
Installs: 95
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/aimeos/prisma
Requires
- php: ^8.1
- ext-fileinfo: *
- ext-gd: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.4
This package is auto-updated.
Last update: 2025-11-16 13:59:17 UTC
README
Light-weight PHP package for integrating multi-media related Large Language Models (LLMs) into your applications using a unified interface.
- Supported providers
- Installation
- API usage
- Common API
- ensure: Ensures that the provider has implemented the method
- has: Tests if the provider has implemented the method
- model: Use the model passed by its name
- withClientOptions: Add options for the Guzzle HTTP client
- withSystemPrompt: Add a system prompt for the LLM
- Image API
- background: Replace background according to the prompt
- describe: Describe the content of an image
- detext: Remove all text from the image
- erase: Erase parts of the image
- imagine: Generate an image from the prompt
- inpaint: Edit an image area according to a prompt
- isolate: Remove the image background
- recognize: Recognizes text in the given image (OCR)
- relocate: Place the foreground object on a new background
- repaint: Repaint an image according to the prompt
- studio: Create studio photo of the foreground object
- uncrop: Extend/outpaint the image
- upscale: Scale up the image
Supported providers
Image
| Clipdrop | Gemini | Ideogram | Imagen | Mistral | OpenAI | RemoveBG | StabilityAI | |
|---|---|---|---|---|---|---|---|---|
| background | yes | - | beta | beta | - | - | - | - |
| describe | - | beta | beta | - | - | beta | - | - |
| detext | yes | - | - | - | - | - | - | - |
| erase | yes | - | - | - | - | - | - | yes |
| imagine | yes | yes | beta | beta | - | yes | - | yes |
| inpaint | - | - | beta | beta | - | yes | - | yes |
| isolate | yes | - | - | - | - | - | yes | yes |
| recognize | - | - | - | - | beta | - | - | - |
| relocate | - | - | - | - | - | - | yes | - |
| repaint | - | yes | beta | - | - | - | - | - |
| studio | yes | - | - | - | - | - | yes | - |
| uncrop | yes | - | - | - | - | - | - | yes |
| upscale | yes | - | beta | beta | - | - | - | yes |
Installation
composer req aimeos/prisma
API usage
Basic usage:
use Aimeos\Prisma\Prisma; $image = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->model( '<modelname>' ) // if model can be selected ->ensure( 'imagine' ) ->imagine( 'a grumpy cat' ) ->binary();
Common API
ensure
Ensures that the provider has implemented the method.
public function ensure( string $method ) : self
- @param string
$methodMethod name - @return Provider
- @throws \Aimeos\Prisma\Exceptions\NotImplementedException
Example:
\Aimeos\Prisma\Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->ensure( 'imagine' );
has
Tests if the provider has implemented the method.
public function has( string $method ) : bool
- @param string
$methodMethod name - @return bool TRUE if implemented, FALSE if absent
Example:
\Aimeos\Prisma\Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->has( 'imagine' );
model
Use the model passed by its name.
Used if the provider supports more than one model and allows to select between the different models. Otherwise, it's ignored.
public function model( ?string $model ) : self
- @param string|null
$modelModel name - @return self Provider interface
Example:
\Aimeos\Prisma\Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->model( 'dall-e-3' );
withClientOptions
Add options for the Guzzle HTTP client.
public function withClientOptions( array `$options` ) : self
- @param array<string, mixed>
$optionsAssociative list of name/value pairs - @return self Provider interface
Example:
\Aimeos\Prisma\Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->withClientOptions( ['timeout' => 120] );
withSystemPrompt
Add a system prompt for the LLM.
It may be used by providers supporting system prompts. Otherwise, it's ignored.
public function withSystemPrompt( ?string $prompt ) : self
- @param string|null
$promptSystem prompt - @return self Provider interface
Example:
\Aimeos\Prisma\Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->withSystemPrompt( 'You are a professional illustrator' );
Image API
Most methods require an image object as input which contains a reference to the image that should be processed. This object can be created by:
use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.php', 'image/png' ); $image = Image::fromLocalPath( 'path/to/image.png', 'image/png' ); $image = Image::fromBinary( 'PNG...', 'image/png' ); $image = Image::fromBase64( 'UE5H...', 'image/png' ); // Laravel only: $image = Image::fromStoragePath( 'path/to/image.png', 'public', 'image/png' );
The last parameter of all methods (mime type) is optional. If it's not passed, the file content will be retrieved to determine the mime type if reqested.
Note: It's best to use fromUrl() if possible because all other formats (binary and base64) can be derived from the URL content but URLs can't be created from binary/base64 data.
The methods return a FileResponse or TextResponse object that contains the returned data and optional meta and usage data.
File data is available by:
$file = $response->binary(); // from binary, base64 and URL $base64 = $response->base64(); // from binary, base64 and URL $url = $response->url(); // only if URL is returned, otherwise NULL
URLs are automatically converted to binary and base64 data if requested and conversion between binary and base64 data is done on request too.
Meta data is available by:
$meta = $response->meta();
It returns an associative array whose content totally depends on the provider.
Usage data is available by:
$usage = $response->usage();
It returns an associative array whose content depends on the provider. If the provider returns usage information, the used array key is available and contains a number. What the number represents depdends on the provider too.
background
Replace image background with a background described by the prompt.
public function background( Image $image, string $prompt, array $options = [] ) : FileResponse
- @param Image
$imageInput image object - @param string
$promptPrompt describing the new background - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->background( $image, 'Golden sunset on a caribbean beach' );
describe
Describe the content of an image.
public function describe( Image $image, ?string $lang = null, array $options = [] ) : TextResponse
- @param Image
$imageInput image object - @param string|null
$langISO language code the description should be generated in - @param array<string, mixed>
$optionsProvider specific options - @return TextResponse Response text
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->describe( $image, 'de' );
detext
Remove all text from the image.
public function detext( Image $image, array $options = [] ) : FileResponse
- @param Image
$imageInput image object - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->detext( `$image` );
erase
Erase parts of the image.
public function erase( Image $image, Image $mask, array $options = [] ) : FileResponse
- @param Image
$imageInput image object - @param Image
$maskMask image object - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
The mask must be an image with black parts (#000000) to keep and white parts (#FFFFFF) to remove.
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $mask = Image::fromBinary( 'PNG...' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->erase( $image, $mask );
imagine
Generate an image from the prompt.
public function imagine( string $prompt, array $images = [], array $options = [] ) : FileResponse
- @param string
$promptPrompt describing the image - @param array<int, \Aimeos\Prisma\Files\Image>
$imagesAssociative list of file name/Image instances - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Supported options:
- Gemini
- Ideogram
- Imagen
- OpenAI GPT image 1
- OpenAI Dall-e-3
- OpenAI Dall-e-2
- StabilityAI Core
- StabilityAI Ultra
- StabilityAI Stable Diffusion 3.5
Example:
use Aimeos\Prisma\Prisma; $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->imagine( 'Futuristic robot looking at a dashboard' );
inpaint
Edit an image by inpainting an area defined by a mask according to a prompt.
public function inpaint( Image $image, Image $mask, string $prompt, array $options = [] ) : FileResponse
- @param Image
$imageInput image object - @param Image
$maskInput mask image object - @param string
$promptPrompt describing the changes - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $mask = Image::fromBinary( 'PNG...' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->inpaint( $image, $mask, 'add a pink flamingo' );
isolate
Remove the image background.
public function isolate( Image $image, array $options = [] ) : FileResponse
- @param Image
$imageInput image object - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->isolate( `$image` );
recognize
Recognizes the text in the given image (OCR).
public function recognize( Image $image, array $options = [] ) : TextResponse;
- @param Image
$imageInput image object - @param array<string, mixed>
$optionsProvider specific options - @return TextResponse Response text object
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->recognize( `$image` );
relocate
Place the foreground object on a new background.
public function relocate( Image $image, Image $bgimage, array $options = [] ) : FileResponse
- @param Image
$imageInput image with foreground object - @param Image
$bgimageBackground image - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $bgimage = Image::fromUrl( 'https://example.com/background.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->relocate( $image, $bgimage );
repaint
Repaint an image according to the prompt.
public function repaint( Image $image, string $prompt, array $options = [] ) : FileResponse
- @param Image
$imageInput image object - @param string
$promptPrompt describing the changes - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->repaint( $image, 'Use a van Goch style' );
studio
Create studio photo from the object in the foreground of the image.
public function studio( Image $image, array $options = [] ) : FileResponse
- @param Image
$imageInput image object - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->studio( `$image` );
uncrop
Extend/outpaint the image.
public function uncrop( Image $image, int $top, int $right, int $bottom, int $left, array $options = [] ) : FileResponse
- @param Image
$imageInput image object - @param int
$topNumber of pixels to extend to the top - @param int
$rightNumber of pixels to extend to the right - @param int
$bottomNumber of pixels to extend to the bottom - @param int
$leftNumber of pixels to extend to the left - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->uncrop( $image, 100, 200, 0, 50 );
upscale
Scale up the image.
public function upscale( Image $image, int $factor, array $options = [] ) : FileResponse
- @param Image
$imageInput image object - @param int
$factorUpscaling factor between 2 and the maximum value supported by the provider - @param array<string, mixed>
$optionsProvider specific options - @return FileResponse Response file
Supported options:
Example:
use Aimeos\Prisma\Prisma; use \Aimeos\Prisma\Files\Image; $image = Image::fromUrl( 'https://example.com/image.png' ); $response = Prisma::image() ->using( '<provider>', ['api_key' => 'xxx']) ->upscale( $image, 4 );