Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/muesli/sticker

A Golang lib to generate placeholder images with text
https://github.com/muesli/sticker

hacktoberfest

Last synced: 12 days ago
JSON representation

A Golang lib to generate placeholder images with text

Awesome Lists containing this project

README

        

sticker
=======

A Golang lib to generate placeholder images with text.

## Installation

Make sure you have a working Go environment (Go 1.9 or higher is required).
See the [install instructions](https://golang.org/doc/install.html).

To install sticker, simply run:

go get github.com/muesli/sticker

To compile it from source:

cd $GOPATH/src/github.com/muesli/sticker
go get -u -v
go build && go test -v

## Example
```go
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:
```go
import "golang.org/x/image/font/gofont/gomono"

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/lorem.png) ![example placeholder with background image](example/motivation.png)

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.

## Development

[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/github.com/muesli/sticker)
[![Build Status](https://travis-ci.org/muesli/sticker.svg?branch=master)](https://travis-ci.org/muesli/sticker)
[![Coverage Status](https://coveralls.io/repos/github/muesli/sticker/badge.svg?branch=master)](https://coveralls.io/github/muesli/sticker?branch=master)
[![Go ReportCard](https://goreportcard.com/badge/muesli/sticker)](https://goreportcard.com/report/muesli/sticker)