Socket
Socket
Sign inDemoInstall

github.com/muesli/sticker

Package Overview
Dependencies
3
Maintainers
0
Alerts
File Explorer

Install Socket

Protect your apps from supply chain attacks

Install

github.com/muesli/sticker

    v0.0.0-20210519044628-82fe18bd329c

Version published
Maintainers
0

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)

FAQs

Last updated on 19 May 2021

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc