Skip to main content

createImage

Generate an image from a template with optional modifications.
$result = $client->createImage(
    string $templateId,
    array $options = []
)

Parameters

templateId
string
required
The template ID (e.g., ‘tpl_xxxxxxxxx’)
options
array
Optional configuration

Returns

Returns an array with either result or error:
// Success
[
    'result' => string // Image data (PNG bytes or SVG string)
]

// Error
[
    'error' => [
        'code' => string,
        'message' => string,
        'docs' => string
    ]
]

Examples

Basic Image Generation

<?php

use Bannerify\Bannerify\BannerifyClient;

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

$result = $client->createImage('tpl_xxxxxxxxx');

if (isset($result['result'])) {
    file_put_contents('output.png', $result['result']);
    echo "Image created successfully!";
}

With Modifications

$result = $client->createImage('tpl_xxxxxxxxx', [
    'modifications' => [
        ['name' => 'title', 'text' => 'Welcome to Bannerify'],
        ['name' => 'subtitle', 'text' => 'Generate images at scale'],
        ['name' => 'logo', 'src' => 'https://example.com/logo.png']
    ]
]);

Generate SVG

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

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

Generate Thumbnail

$result = $client->createImage('tpl_xxxxxxxxx', [
    'thumbnail' => true
]);

Error Handling

$result = $client->createImage('tpl_xxxxxxxxx', [
    'modifications' => [
        ['name' => 'title', 'text' => 'Test']
    ]
]);

if (isset($result['error'])) {
    echo "Error Code: " . $result['error']['code'] . "\n";
    echo "Message: " . $result['error']['message'] . "\n";
    echo "Documentation: " . $result['error']['docs'] . "\n";
} else {
    // Save the image
    file_put_contents('output.png', $result['result']);
}

Use Cases

Dynamic Marketing Banners

$products = [
    ['name' => 'Product A', 'price' => '$29.99', 'image' => 'https://example.com/a.jpg'],
    ['name' => 'Product B', 'price' => '$39.99', 'image' => 'https://example.com/b.jpg'],
];

foreach ($products as $index => $product) {
    $result = $client->createImage('tpl_product_banner', [
        'modifications' => [
            ['name' => 'product_name', 'text' => $product['name']],
            ['name' => 'price', 'text' => $product['price']],
            ['name' => 'product_image', 'src' => $product['image']]
        ]
    ]);
    
    if (isset($result['result'])) {
        file_put_contents("banner_{$index}.png", $result['result']);
    }
}

Social Media Posts

$result = $client->createImage('tpl_social_post', [
    'modifications' => [
        ['name' => 'headline', 'text' => 'New Blog Post!'],
        ['name' => 'author', 'text' => 'John Doe'],
        ['name' => 'date', 'text' => date('F j, Y')]
    ]
]);