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

## CreateImage

Generate an image from a template with optional modifications.

```go theme={null}
func (c *BannerifyClient) CreateImage(
    ctx context.Context,
    templateID string,
    opts *CreateImageOptions,
) Response
```

### Parameters

<ParamField path="ctx" type="context.Context" required>
  Context for the request
</ParamField>

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

<ParamField path="opts" type="*CreateImageOptions">
  Optional configuration

  <Expandable title="properties">
    <ParamField path="Modifications" type="[]Modification">
      Array of modifications to apply to the template

      <Expandable title="modification">
        <ParamField path="Name" type="string" required>
          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="*bool">
          Toggle element visibility
        </ParamField>

        <ParamField path="Color" type="string">
          Element color
        </ParamField>
      </Expandable>
    </ParamField>

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

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

### Returns

Returns a `Response` struct with either `Result` or `Error`:

```go theme={null}
type Response struct {
    Result interface{} // []byte containing image data
    Error  *ErrorResponse
}
```

## Examples

### Basic Image Generation

```go theme={null}
package main

import (
    "context"
    "os"
    
    "github.com/bannerify/bannerify-go"
)

func main() {
    client := bannerify.NewBannerifyClient("your-api-key")
    
    result := client.CreateImage(context.Background(), "tpl_xxxxxxxxx", nil)
    
    if result.Error == nil {
        imageData := result.Result.([]byte)
        os.WriteFile("output.png", imageData, 0644)
    }
}
```

### With Modifications

```go theme={null}
result := client.CreateImage(ctx, "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
    Modifications: []bannerify.Modification{
        {Name: "title", Text: "Welcome to Bannerify"},
        {Name: "subtitle", Text: "Generate images at scale"},
        {Name: "logo", Src: "https://example.com/logo.png"},
    },
})
```

### Generate WebP

```go theme={null}
result := client.CreateImage(ctx, "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
    Format: "webp",
    Modifications: []bannerify.Modification{
        {Name: "title", Text: "WebP Output"},
    },
})

if result.Error == nil {
    webpData := result.Result.([]byte)
    os.WriteFile("output.webp", webpData, 0644)
}
```

### Generate Thumbnail

```go theme={null}
result := client.CreateImage(ctx, "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
    Thumbnail: true,
})
```

### Error Handling

```go theme={null}
result := client.CreateImage(ctx, "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
    Modifications: []bannerify.Modification{
        {Name: "title", Text: "Test"},
    },
})

if result.Error != nil {
    fmt.Printf("Error Code: %s\n", result.Error.Error.Code)
    fmt.Printf("Message: %s\n", result.Error.Error.Message)
    fmt.Printf("Documentation: %s\n", result.Error.Error.Docs)
} else {
    imageData := result.Result.([]byte)
    os.WriteFile("output.png", imageData, 0644)
}
```

## Use Cases

### Dynamic Marketing Banners

```go theme={null}
products := []struct {
    Name  string
    Price string
    Image string
}{
    {"Product A", "$29.99", "https://example.com/a.jpg"},
    {"Product B", "$39.99", "https://example.com/b.jpg"},
}

for i, product := range products {
    result := client.CreateImage(ctx, "tpl_product_banner", &bannerify.CreateImageOptions{
        Modifications: []bannerify.Modification{
            {Name: "product_name", Text: product.Name},
            {Name: "price", Text: product.Price},
            {Name: "product_image", Src: product.Image},
        },
    })
    
    if result.Error == nil {
        imageData := result.Result.([]byte)
        os.WriteFile(fmt.Sprintf("banner_%d.png", i), imageData, 0644)
    }
}
```

### Social Media Posts

```go theme={null}
import "time"

result := client.CreateImage(ctx, "tpl_social_post", &bannerify.CreateImageOptions{
    Modifications: []bannerify.Modification{
        {Name: "headline", Text: "New Blog Post!"},
        {Name: "author", Text: "John Doe"},
        {Name: "date", Text: time.Now().Format("January 2, 2006")},
    },
})
```

### Toggle Visibility

```go theme={null}
func boolPtr(b bool) *bool {
    return &b
}

result := client.CreateImage(ctx, "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
    Modifications: []bannerify.Modification{
        {Name: "watermark", Visible: boolPtr(false)},
        {Name: "badge", Visible: boolPtr(true)},
    },
})
```
