createImage
Generate an image from a template with optional modifications.Copy
$result = $client->createImage(
string $templateId,
array $options = []
)
Parameters
The template ID (e.g., ‘tpl_xxxxxxxxx’)
Optional configuration
Show properties
Show properties
Output format: ‘png’ or ‘svg’
Generate thumbnail version
Returns
Returns an array with eitherresult or error:
Copy
// Success
[
'result' => string // Image data (PNG bytes or SVG string)
]
// Error
[
'error' => [
'code' => string,
'message' => string,
'docs' => string
]
]
Examples
Basic Image Generation
Copy
<?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
Copy
$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
Copy
$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
Copy
$result = $client->createImage('tpl_xxxxxxxxx', [
'thumbnail' => true
]);
Error Handling
Copy
$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
Copy
$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
Copy
$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')]
]
]);