> ## Documentation Index
> Fetch the complete documentation index at: https://documentation.bannerify.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Image

> Generate images from templates using the PHP SDK

## createImage

Generate an image from a template with optional modifications.

```php theme={null}
$result = $client->createImage(
    string $templateId,
    array $options = []
)
```

### Parameters

<ParamField path="templateId" type="string" required>
  The template ID (e.g., 'tpl\_xxxxxxxxx')
</ParamField>

<ParamField path="options" type="array">
  Optional configuration

  <Expandable title="properties">
    <ParamField path="modifications" type="array">
      Array of modifications to apply to the template

      <Expandable title="modification">
        <ParamField path="name" type="string">
          Element name to modify
        </ParamField>

        <ParamField path="text" type="string">
          New text content
        </ParamField>

        <ParamField path="src" type="string">
          New image source URL
        </ParamField>

        <ParamField path="visible" type="boolean">
          Toggle element visibility
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField path="format" type="string" default="png">
      Output format: 'png', 'jpeg', or 'webp'
    </ParamField>

    <ParamField path="thumbnail" type="boolean" default="false">
      Generate thumbnail version
    </ParamField>
  </Expandable>
</ParamField>

### Returns

Returns an array with either `result` or `error`:

```php theme={null}
// Success
[
    'result' => string // Image data (PNG/JPEG/WebP bytes)
]

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

## Examples

### Basic Image Generation

```php theme={null}
<?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

```php theme={null}
$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 WebP

```php theme={null}
$result = $client->createImage('tpl_xxxxxxxxx', [
    'format' => 'webp',
    'modifications' => [
        ['name' => 'title', 'text' => 'WebP Output']
    ]
]);

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

### Generate Thumbnail

```php theme={null}
$result = $client->createImage('tpl_xxxxxxxxx', [
    'thumbnail' => true
]);
```

### Error Handling

```php theme={null}
$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

```php theme={null}
$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

```php theme={null}
$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')]
    ]
]);
```
