nicodemuz/php-getimg.ai
最新稳定版本:v1.0.1
Composer 安装命令:
composer require nicodemuz/php-getimg.ai
包简介
PHP SDK for GetImg.ai image generation service.
README 文档
README
nicodemuz/php-getimg.ai is a modern, lightweight PHP library designed to integrate seamlessly with the GetImg.ai image generation API. Quickly generate stunning AI-powered images for your projects with just a few lines of code.
This package is currently under development. There is only support for text-to-image generation & inpainting. Pull requests for other features are welcome.
Features 🚀
- PSR-18 and PSR-17 Compatibility: Fully compliant with PSR-18 (HTTP Client) and PSR-17 (HTTP Factories) standards, ensuring seamless integration with any compatible HTTP client and factory implementation.
- Comprehensive API Coverage: Access all GetImg.ai image generation features.
- Flexible Configuration: Customize HTTP client, request factories, and other dependencies to suit your project.
- Lightweight: Minimal dependencies for fast and efficient performance.
Installation 💻
Install the package via Composer:
composer require nicodemuz/php-getimg.ai
Installation 💻
Install the package via Composer:
composer require nicodemuz/php-getimg.ai
Installing PSR-17 and PSR-18 dependencies
To use this library, you'll need PSR-17 (HTTP Factories) and PSR-18 (HTTP Client) compatible packages. If you don't already have them, you can install popular implementations such as:
-
Guzzle (for PSR-18) and Nyholm/psr7 (for PSR-17):
composer require guzzlehttp/guzzle nyholm/psr7
-
Symfony HTTP Client (alternative for PSR-18) and Symfony HTTP Factories (for PSR-17):
composer require symfony/http-client symfony/psr-http-message-bridge
After installation, initialize the required dependencies in your project as shown in the usage example.
Usage 📖
Basic Example
<?php require 'vendor/autoload.php'; use Nicodemuz\PhpGetImgAi\GetImgAiClient; use Nicodemuz\PhpGetImgAi\Request\TextToImageRequest; use GuzzleHttp\Client as HttpClient; use Nyholm\Psr7\Factory\Psr17Factory; // Initialize the required dependencies $httpClient = new HttpClient(); $requestFactory = new Psr17Factory(); $streamFactory = new Psr17Factory(); // Initialize the GetImgAiClient with your API key $apiKey = 'your-api-key-here'; $getImgClient = new GetImgAiClient($apiKey, $httpClient, $requestFactory, $streamFactory); try { // Create a request for text-to-image generation $textToImageRequest = new TextToImageRequest( prompt: 'A futuristic city skyline at sunset, cyberpunk style', model: 'flux-schnell', width: 1024, height: 1024, steps: 4, seed: null, // Optional seed for reproducibility outputFormat: 'jpeg', responseFormat: 'url' ); // Generate the image $response = $getImgClient->textToImage($textToImageRequest); // Output the results echo "Image URL: " . $response->getUrl() . PHP_EOL; echo "Seed Used: " . $response->getSeed() . PHP_EOL; echo "Cost: $" . $response->getCost() . PHP_EOL; // Optionally, download the image $imageData = file_get_contents($response->getUrl()); file_put_contents('generated_image.jpeg', $imageData); echo "Image saved as 'generated_image.jpeg'." . PHP_EOL; } catch (Exception $e) { // Handle errors echo "Error: " . $e->getMessage() . PHP_EOL; }
Requirements 📋
- PHP 8.3 or higher
- Composer
Contributing 🤝
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new feature branch.
- Submit a pull request with a clear description of your changes.
License 📜
This library is open-sourced software licensed under the MIT License.
Support & Feedback ✉️
If you encounter issues or have suggestions, feel free to open an issue.
Authors
🌟 Happy Generating!
统计信息
- 总下载量: 638
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-02