> ## 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 Python SDK

## create\_image

Generate an image from a template with optional modifications.

```python theme={null}
client.create_image(
    template_id: str,
    modifications: Optional[List[Dict[str, Any]]] = None,
    format: str = "png",
    thumbnail: bool = False
) -> Dict[str, Any]
```

### Parameters

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

<ParamField path="modifications" type="list">
  Array of modifications to apply to the template

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

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

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

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

    <ParamField path="color" type="str">
      Element color
    </ParamField>
  </Expandable>
</ParamField>

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

<ParamField path="thumbnail" type="bool" default="False">
  Generate thumbnail version
</ParamField>

### Returns

Returns a dict with either `result` or `error`:

```python theme={null}
# Success
{
    "result": bytes  # Image data
}

# Error
{
    "error": {
        "code": str,
        "message": str,
        "docs": str
    }
}
```

## Examples

### Basic Image Generation

```python theme={null}
from bannerify import BannerifyClient

client = BannerifyClient("your-api-key")

result = client.create_image("tpl_xxxxxxxxx")

if "result" in result:
    with open("output.png", "wb") as f:
        f.write(result["result"])
    print("Image created successfully!")
```

### With Modifications

```python theme={null}
result = client.create_image(
    "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

```python theme={null}
result = client.create_image(
    "tpl_xxxxxxxxx",
    format="webp",
    modifications=[
        {"name": "title", "text": "WebP Output"}
    ]
)

if "result" in result:
    with open("output.webp", "wb") as f:
        f.write(result["result"])
```

### Generate Thumbnail

```python theme={null}
result = client.create_image(
    "tpl_xxxxxxxxx",
    thumbnail=True
)
```

### Error Handling

```python theme={null}
result = client.create_image(
    "tpl_xxxxxxxxx",
    modifications=[
        {"name": "title", "text": "Test"}
    ]
)

if "error" in result:
    print(f"Error Code: {result['error']['code']}")
    print(f"Message: {result['error']['message']}")
    print(f"Documentation: {result['error']['docs']}")
else:
    with open("output.png", "wb") as f:
        f.write(result["result"])
```

## Use Cases

### Dynamic Marketing Banners

```python 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"},
]

for i, product in enumerate(products):
    result = client.create_image(
        "tpl_product_banner",
        modifications=[
            {"name": "product_name", "text": product["name"]},
            {"name": "price", "text": product["price"]},
            {"name": "product_image", "src": product["image"]}
        ]
    )
    
    if "result" in result:
        with open(f"banner_{i}.png", "wb") as f:
            f.write(result["result"])
```

### Social Media Posts

```python theme={null}
from datetime import datetime

result = client.create_image(
    "tpl_social_post",
    modifications=[
        {"name": "headline", "text": "New Blog Post!"},
        {"name": "author", "text": "John Doe"},
        {"name": "date", "text": datetime.now().strftime("%B %d, %Y")}
    ]
)
```

### Toggle Visibility

```python theme={null}
result = client.create_image(
    "tpl_xxxxxxxxx",
    modifications=[
        {"name": "watermark", "visible": False},
        {"name": "badge", "visible": True}
    ]
)
```
