Navigation

PHP

Overview

PHP client for Bannerify

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.

Examples

Open only what you need

Success
[
    'result' => mixed // the result depends on what method you called
]
Error
[
    'error' => [
        // A machine readable error code
        'code' => 'ERROR_CODE',
        
        // A link to our documentation explaining this error
        'docs' => 'https://bannerify.co/docs',
        
        // A human readable explanation
        'message' => 'Error message'
    ]
]

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

#apiKeystringrequired

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 WebP Image

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

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

Generate Signed URL

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

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