Skip to main content
Get started with our PHP SDK, bannerify/bannerify, for a typed and efficient experience. This SDK allows you to interact with our API without having to make HTTP requests directly.

Install

Install via Composer:
composer require bannerify/bannerify

Instantiate

If you want to use SDK, you will need your API key — you can create a new one in the settings.
<?php

use Bannerify\Bannerify\BannerifyClient;

$client = new BannerifyClient('your-api-key');

Response format

To make error handling explicit and prevent forgotten error checks, we return errors as part of the response structure. Every method returns an array with either a result or an error field, never both and never none.
[
    'result' => mixed // the result depends on what method you called
]

Checking for errors

To check for errors, use the error key in the response:
<?php

use Bannerify\Bannerify\BannerifyClient;

$client = new BannerifyClient('your-api-key');
$result = $client->createImage('tpl_xxxxxxxxx', [
    'modifications' => [
        ['name' => 'title', 'text' => 'Hello World']
    ]
]);

if (isset($result['error'])) {
    // Handle error
    echo "Error: " . $result['error']['message'];
    return;
}

// Process the result
file_put_contents('output.png', $result['result']);

Options

The constructor accepts some options to customize the behavior:

API Key

apiKey
string
required
Your project’s API key
$client = new BannerifyClient('my-api-key');

Base URL

Override the default API base URL:
$client = new BannerifyClient('my-api-key', [
    'baseUrl' => 'https://api.bannerify.co'
]);

Examples

Generate PNG 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']);
}

Generate SVG Image

$result = $client->createImage('tpl_xxxxxxxxx', [
    'format' => 'svg',
    'modifications' => [
        ['name' => 'title', 'text' => 'Hello SVG']
    ]
]);

if (isset($result['result'])) {
    file_put_contents('output.svg', $result['result']);
}

Generate Signed URL

$signedUrl = $client->generateImageSignedUrl('tpl_xxxxxxxxx', [
    'modifications' => [
        ['name' => 'title', 'text' => 'Dynamic Title']
    ]
]);

echo "<img src='{$signedUrl}' alt='Generated Image' />";