定制 bannerify/bannerify 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

License PHP Version

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 URL
  • timeout (float): Request timeout in seconds

createImage

createImage(string $templateId, array $options = []): array

Options:

  • modifications (array): Array of modifications
  • format (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

License

MIT License - see LICENSE file for details

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-14