CreateImage
Generate an image from a template with optional modifications.Copy
func (c *BannerifyClient) CreateImage(
ctx context.Context,
templateID string,
opts *CreateImageOptions,
) Response
Parameters
Context for the request
The template ID (e.g., ‘tpl_xxxxxxxxx’)
Optional configuration
Show properties
Show properties
Output format: “png” or “svg”
Generate thumbnail version
Returns
Returns aResponse struct with either Result or Error:
Copy
type Response struct {
Result interface{} // []byte containing image data
Error *ErrorResponse
}
Examples
Basic Image Generation
Copy
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
Copy
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 SVG
Copy
result := client.CreateImage(ctx, "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
Format: "svg",
Modifications: []bannerify.Modification{
{Name: "title", Text: "SVG Output"},
},
})
if result.Error == nil {
svgData := result.Result.([]byte)
os.WriteFile("output.svg", svgData, 0644)
}
Generate Thumbnail
Copy
result := client.CreateImage(ctx, "tpl_xxxxxxxxx", &bannerify.CreateImageOptions{
Thumbnail: true,
})
Error Handling
Copy
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
Copy
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
Copy
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
Copy
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)},
},
})