# Create images and PDFs in PHP

> Generate an image, a PDF, or a hosted image URL from a template with the PHP SDK.

Canonical: https://bannerify.co/docs/sdk/php/apis/create-image

Each method takes a template id and an options array. Every option is optional.

## Create an image

`createImage` renders the template and returns the image bytes.

<ParamField body="templateId" type="string" required>
  The template id, for example `tpl_xxx`.
</ParamField>

<ParamField body="modifications" type="array">
  The values to put into the template's layers. Each entry is an array that names a layer with `name`. Layers you leave out keep the values from the template. [Modifications](https://bannerify.co/docs/essentials/modifications) lists the fields each layer accepts.
</ParamField>

<ParamField body="format" type="string" default="png">
  The image format: `png`, `jpeg`, or `webp`.
</ParamField>

```php
$result = $client->createImage('tpl_xxx', [
    'modifications' => [
        ['name' => 'headline', 'text' => 'Launch promo'],
        ['name' => 'price', 'text' => '$29'],
    ],
    'format' => 'webp',
]);

if (isset($result['error'])) {
    throw new RuntimeException($result['error']['message']);
}

file_put_contents('launch-promo.webp', $result['result']);
```

In a web request, send the bytes with the matching `Content-Type` header, for example `image/webp`.

## Create a PDF

`createPdf` takes the same `modifications` option. It has no `format` option.

```php
$result = $client->createPdf('tpl_invoice', [
    'modifications' => [
        ['name' => 'customer', 'text' => 'Acme Studio'],
        [
            'name' => 'line-items',
            'columns' => ['Item', 'Qty', 'Total'],
            'rows' => [['Item' => 'Automate plan', 'Qty' => 1, 'Total' => '$29.00']],
        ],
    ],
]);

if (isset($result['error'])) {
    throw new RuntimeException($result['error']['message']);
}

file_put_contents('invoice.pdf', $result['result']);
```

## Create a stored image

`createStoredImage` renders the image, saves it on the Bannerify CDN, and returns a URL instead of the bytes. The URL starts with `https://images.bannerify.co/files/`. Use it when you want to put the link in an email, a database row, or a no-code tool.

It takes the same options as `createImage`.

```php
$result = $client->createStoredImage('tpl_xxx', [
    'modifications' => [
        ['name' => 'headline', 'text' => 'Welcome back'],
    ],
]);

if (isset($result['error'])) {
    throw new RuntimeException($result['error']['message']);
}

echo $result['result'];
```

The PHP SDK cannot send `s3Config`. To save the file to your own bucket, call [Create stored image](https://bannerify.co/docs/api-reference/endpoint/create-stored-image) over REST.

## Handle the result

All three methods return `['result' => ...]` or `['error' => ...]`. See [Handle errors](https://bannerify.co/docs/sdk/php/overview#handle-errors).

## Related

- [Previous: PHP SDK](https://bannerify.co/docs/sdk/php/overview)
- [Next: Render videos in PHP](https://bannerify.co/docs/sdk/php/apis/render-video)
- [Documentation index](https://bannerify.co/docs/llms.txt)
