azlanali076 / image-generator
A Laravel package for generating images using the OpenAI API. This package provides an easy-to-use interface for interacting with the OpenAI API to generate images based on text prompts.
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/azlanali076/image-generator
Requires
- php: ^7.4|^8.0|^8.1
- guzzlehttp/guzzle: ^7.9
- illuminate/support: ^10.48
README
A Laravel package for generating images using the OpenAI API. This package provides an easy-to-use interface for interacting with the OpenAI API to generate images based on text prompts.
Installation
You can install the package via Composer:
composer require azlanali076/image-generator
Configuration
1. Publish the Configuration File
Publish the configuration file to your application's config directory:
php artisan vendor:publish --provider="Azlanali076\ImageGenerator\ImageGeneratorServiceProvider"
2. Set Up Your API Key
Make sure to add your API key to your .env file:
OPENAI_API_KEY=your-openai-api-key
Usage
You can use the package by calling the generate method on the facade ImageGenerator.
use Azlanali076\ImageGenerator\Facades\ImageGenerator; // Generate an image $imageResponse = ImageGenerator::generate( "A Cute White Cat" ); // Check if the response is successful if ($imageResponse['success']) { // Retrieve the image URL $url = $imageResponse['data'][0]['url']; echo "Image URL: " . $url; } else { // Handle the error echo "Error: " . $imageResponse['message']; }
Constants
ImageGenerator::QUALITY_STANDARDConstant for thestandardimage quality.ImageGenerator::QUALITY_HDConstant for thehdimage quality.ImageGenerator::STYLE_NATURALConstant for thenaturalimage style.ImageGenerator::STYLE_VIVIDConstant for thevividimage style.ImageGenerator::RESPONSE_FORMAT_URLConstant for theurlresponse format.ImageGenerator::RESPONSE_FORMAT_BASE64Constant for theb64_json(base 64) response format.
Parameters
string $promptThe text prompt for generating the image.int|null $widthThe width of the generated image (default is 1024 if null).int|null $heightThe height of the generated image (default is 1024 if null).string|null $qualityThe quality of the image (default is 'standard').string|null $styleThe style of the image (default is 'vivid').string|null $responseFormatThe format of the response (default is 'url').
Response Format
successA boolean indicating whether the request was successful.dataThe data returned from the API (includes the image URL if successful).messageAn error message if the request was not successful.codeAn error code if the request was not successful.