bannerify/bannerify
最新稳定版本:v0.1.0
Composer 安装命令:
composer require bannerify/bannerify
包简介
Official PHP SDK for Bannerify API - Generate images and PDFs at scale
README 文档
README
Official PHP SDK for Bannerify - Generate images and PDFs at scale via API.
Installation
Install via Composer:
composer require bannerify/bannerify
Quick Start
<?php require 'vendor/autoload.php'; use Bannerify\Client; // Create client with your API key $client = new Client('your-api-key'); // Generate an image $result = $client->createImage('tpl_xxxxxxxxx', [ 'modifications' => [ ['name' => 'title', 'text' => 'Hello World'], ['name' => 'subtitle', 'text' => 'From PHP SDK'] ] ]); if (isset($result['result'])) { file_put_contents('output.png', $result['result']); echo "Image created successfully!"; } else { echo "Error: " . $result['error']['message']; }
Features
- 🚀 Simple, intuitive API
- 🔒 Type-safe with PHPStan support
- ⚡ Built on Guzzle for reliability
- 🎯 Result/Error pattern for explicit error handling
- 📝 Comprehensive documentation
- ✅ Well-tested
Usage
Creating Images
// Generate PNG $result = $client->createImage('tpl_xxxxxxxxx', [ 'modifications' => [ ['name' => 'title', 'text' => 'My Title'], ['name' => 'image', 'src' => 'https://example.com/image.jpg'] ] ]); // Generate WebP $result = $client->createImage('tpl_xxxxxxxxx', [ 'format' => 'webp', 'modifications' => [ ['name' => 'title', 'text' => 'My Title'] ] ]); // Generate thumbnail $result = $client->createImage('tpl_xxxxxxxxx', [ 'thumbnail' => true ]);
Creating PDFs
$result = $client->createPdf('tpl_xxxxxxxxx', [ 'modifications' => [ ['name' => 'title', 'text' => 'Invoice #123'] ] ]); if (isset($result['result'])) { file_put_contents('invoice.pdf', $result['result']); }
Generating Signed URLs
$signedUrl = $client->generateImageSignedUrl('tpl_xxxxxxxxx', [ 'modifications' => [ ['name' => 'title', 'text' => 'Dynamic Title'] ], 'format' => 'png' ]); // Use in HTML echo "<img src='{$signedUrl}' alt='Generated Image' />";
Error Handling
$result = $client->createImage('tpl_xxxxxxxxx'); if (isset($result['error'])) { $error = $result['error']; echo "Error Code: " . $error['code'] . "\n"; echo "Message: " . $error['message'] . "\n"; echo "Docs: " . $error['docs'] . "\n"; } else { file_put_contents('output.png', $result['result']); }
API Reference
Constructor
new Client(string $apiKey, array $options = [])
Options:
baseUrl(string): API base URLtimeout(float): Request timeout in seconds
createImage
createImage(string $templateId, array $options = []): array
Options:
modifications(array): Array of modificationsformat(string): 'png', 'jpeg', or 'webp'thumbnail(bool): Generate thumbnail
Returns: Array with result (string) or error (array)
createPdf
createPdf(string $templateId, array $options = []): array
createStoredImage
createStoredImage(string $templateId, array $options = []): array
generateImageSignedUrl
generateImageSignedUrl(string $templateId, array $options = []): string
Examples
Generate Multiple Images
$products = [ ['name' => 'Product A', 'price' => '$29.99'], ['name' => 'Product B', 'price' => '$39.99'], ]; foreach ($products as $i => $product) { $result = $client->createImage('tpl_product_banner', [ 'modifications' => [ ['name' => 'product_name', 'text' => $product['name']], ['name' => 'price', 'text' => $product['price']] ] ]); if (isset($result['result'])) { file_put_contents("banner_{$i}.png", $result['result']); } }
Email Campaigns
foreach ($recipients as $recipient) { $signedUrl = $client->generateImageSignedUrl('tpl_email_header', [ 'modifications' => [ ['name' => 'name', 'text' => "Hi, {$recipient['name']}!"] ] ]); // Use $signedUrl in email HTML }
Documentation
Full documentation available at https://bannerify.co/docs/sdk/php/overview
Support
- Documentation: https://bannerify.co/docs
- Issues: https://github.com/bannerify/bannerify-php/issues
- Email: support@bannerify.co
License
MIT License - see LICENSE file for details
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-14