Download the PHP package florinnichifiriuc/stable-diffusion-php-client without Composer
On this page you can find all versions of the php package florinnichifiriuc/stable-diffusion-php-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download florinnichifiriuc/stable-diffusion-php-client
More information about florinnichifiriuc/stable-diffusion-php-client
Files in florinnichifiriuc/stable-diffusion-php-client
Package stable-diffusion-php-client
Short Description A PHP client library for Stable Diffusion API
License MIT
Informations about the package stable-diffusion-php-client
Stable Diffusion PHP Client
A PHP client library for interacting with the Stable Diffusion API. This library allows you to integrate Stable Diffusion's text-to-image generation capabilities into your PHP applications, including Laravel projects.
Table of Contents
- Features
- Requirements
- Installation
- 1. Install via Composer
- 2. Set Up Stable Diffusion API
- Configuration
- Usage
- Basic Example
- Using Models
- Additional Methods
- Laravel Integration
- Advanced Usage
- Available Methods
- Error Handling
- Contributing
- License
Version 1.0.3
Features
- Interact with the Stable Diffusion API using PHP.
- Generate images from text prompts (
txt2img
). - Generate images from existing images (
img2img
). - Inpainting support with masking (
inpaint
). - Retrieve available models and samplers.
- Asynchronous image generation (
txt2imgAsync
). - Progress tracking during image generation.
- Fetch and update configurations.
Requirements
- PHP 7.4 or higher.
- Composer.
- Guzzle HTTP client (automatically installed via Composer).
- Locally running Stable Diffusion instance with API enabled.
Installation
1. Install via Composer
Run the following command in your project's root directory:
Replace florinnichifiriuc/stable-diffusion-php-client
with the actual package name as published on Packagist.
2. Set Up Stable Diffusion API
Ensure that your Stable Diffusion instance is running with the API enabled.
Steps:
- Install Stable Diffusion with Automatic1111 Web UI if you haven't already.
-
Enable the API by starting the Web UI with the
--api
flag:- By default, the API runs at
http://127.0.0.1:7860
.
- By default, the API runs at
Configuration
Environment Variables
In your project's .env
file (or equivalent configuration), add the following line:
Usage
Basic Example
Using Models
Additional Methods
img2img()
– Create images from existing images.inpaint()
– Perform inpainting using masks.txt2imgAsync()
– Perform asynchronous image generation.getProgress()
– Fetch progress of image generation.getConfig()
– Fetch current configuration.setConfig()
– Set configurations like default resolution or sampler.fetchResultByTaskId()
– Get the result of async image generation using task ID.
Laravel Integration
Controller Example
File: app/Http/Controllers/ImageGenerationController.php
Available Methods
txt2img(array $params)
– Generates images from text prompts.img2img(array $params, string $inputImage)
– Generates images from an existing input image.inpaint(array $params, string $inputImage, string $maskImage)
– Performs inpainting on an image using a mask.txt2imgAsync(array $params)
– Asynchronously generates images and returns a task ID.fetchResultByTaskId(string $taskId)
– Fetches the result of asynchronous image generation.getModels()
– Retrieves the available models installed.setModel($modelTitle)
– Sets the model for image generation.getSamplers()
– Fetches available samplers.getUpscalers()
– Fetches available upscalers.getProgress()
– Retrieves progress for ongoing image generation.getConfig()
– Fetches current configuration settings.setConfig(array $config)
– Updates the configuration settings (e.g., default resolution, sampler).
Error Handling
The library throws exceptions when:
- The specified model does not exist (
InvalidArgumentException
). - HTTP requests fail or the API returns an error.
Contributing
Contributions are welcome! If you encounter bugs or have feature requests, please open an issue or submit a pull request on GitHub.
Development Setup
-
Clone the Repository:
- Install Dependencies:
License
This project is licensed under the MIT License. See the LICENSE file for details.