# Create images and PDFs in Go

> Generate an image or a PDF from a template with the Go SDK.

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

Both methods take a `context.Context` and a template id. The examples use the `ptr` helper from the [overview](https://bannerify.co/docs/sdk/go/overview#generate-an-image).

## Create an image

`CreateImage` renders the template and returns the image bytes in `Result`. It takes a `*CreateImageOptions`, and `nil` uses the defaults.

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

<ParamField body="Modifications" type="[]Modification">
  The values to put into the template's layers. Each entry 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>

```go
result := client.CreateImage(ctx, "tpl_xxx", &bannerify.CreateImageOptions{
	Modifications: []bannerify.Modification{
		{Name: "headline", Text: ptr("Launch promo")},
		{Name: "price", Text: ptr("$29")},
	},
	Format: "webp",
})
if result.Error != nil {
	return fmt.Errorf("create image: %s", result.Error.Message)
}

return os.WriteFile("launch-promo.webp", result.Result, 0o644)
```

## Create a PDF

`CreatePDF` takes the modifications directly. It has no format option.

```go
result := client.CreatePDF(ctx, "tpl_invoice", []bannerify.Modification{
	{Name: "customer", Text: ptr("Acme Studio")},
	{
		Name:    "line-items",
		Columns: ptr([]string{"Item", "Qty", "Total"}),
		Rows: ptr([]interface{}{
			map[string]interface{}{"Item": "Automate plan", "Qty": 1, "Total": "$29.00"},
		}),
	},
})
if result.Error != nil {
	return fmt.Errorf("create pdf: %s", result.Error.Message)
}

return os.WriteFile("invoice.pdf", result.Result, 0o644)
```

## Modification fields

`Modification` has these fields. All of them except `Name` are pointers.

| Field | Type | Layer |
| --- | --- | --- |
| `Name` | `string` | Names the layer to change |
| `Text` | `*string` | Text |
| `Src` | `*string` | Image |
| `Color` | `*string` | Color |
| `Visible` | `*bool` | Shows or hides the layer |
| `Qrcode` | `*string` | QR code |
| `Barcode` | `*string` | Barcode |
| `Star` | `*float32` | Star rating |
| `Columns` | `*[]string` | Table columns |
| `Rows` | `*[]interface{}` | Table, chart, or key value rows |

The struct has no `Title` or `Date` field, so you cannot set an alert or a signature layer with it. Call the [REST API](https://bannerify.co/docs/api-reference/endpoint/create-image) for those layers.

## Handle the result

Both methods return a `*Response`. See [Handle errors](https://bannerify.co/docs/sdk/go/overview#handle-errors).

## Related

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