package module
Version: v0.0.0-...-82fe18b Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2021 License: MIT Imports: 9 Imported by: 0



A Golang lib to generate placeholder images with text.


Make sure you have a working Go environment (Go 1.9 or higher is required). See the install instructions.

To install sticker, simply run:

go get

To compile it from source:

cd $GOPATH/src/
go get -u -v
go build && go test -v


gen, err := sticker.NewImageGenerator(sticker.Options{
    TTFPath:         "/usr/share/fonts/TTF/Roboto-Bold.ttf",
    MarginRatio:     0.2,
    Foreground:      color.RGBA{0x96, 0x96, 0x96, 0xff},
    Background:      color.RGBA{0xcc, 0xcc, 0xcc, 0xff},
    BackgroundImage: img,
img, err := gen.NewPlaceholder("Lorem ipsum!", 400, 200)

You can also pass a []byte containing the font:

import ""

gen, err := sticker.NewImageGenerator(sticker.Options{
    TTF:             gomono.TTF,
    MarginRatio:     0.2,
    Foreground:      color.RGBA{0x96, 0x96, 0x96, 0xff},
    Background:      color.RGBA{0xcc, 0xcc, 0xcc, 0xff},

example placeholder example placeholder with background image

sticker will automatically pick a suitable font size, so the text will always fit neatly inside the image.

If you supply a background image, it will automatically be cropped and scaled (while maintaining its original aspect ratio) to the desired output size.


GoDoc Build Status Coverage Status Go ReportCard




This section is empty.


View Source
var (
	// ErrInvalidDimensions gets returned when the requested image has an invalid width or height
	ErrInvalidDimensions = errors.New("values for width or height must be positive")

	// ErrMissingFontOption gets returned when there's no font specified in the options
	ErrMissingFontOption = errors.New("no font option specified")


This section is empty.


type ImageGenerator

type ImageGenerator struct {
	// contains filtered or unexported fields

ImageGenerator lets you generate images & placeholders

func NewImageGenerator

func NewImageGenerator(options Options) (*ImageGenerator, error)

NewImageGenerator returns a new ImageGenerator

func (*ImageGenerator) NewPlaceholder

func (p *ImageGenerator) NewPlaceholder(text string, width, height int) (image.Image, error)

NewPlaceholder returns a placeholder image with the given text, width & height

type Options

type Options struct {
	TTFPath         string
	TTF             []byte
	Foreground      color.RGBA
	Background      color.RGBA
	BackgroundImage image.Image
	MarginRatio     float64

Options contains all the settings for an ImageGenerator

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL