Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/muesli/sticker
- Owner: muesli
- License: mit
- Created: 2017-08-06T20:20:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-19T04:46:33.000Z (over 3 years ago)
- Last Synced: 2024-10-04T11:32:26.967Z (about 1 month ago)
- Topics: hacktoberfest
- Language: Go
- Size: 141 KB
- Stars: 79
- Watchers: 5
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)