timg

package module
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

README

timg

Creates an image from txt

Documentation

Overview

Package timg allows you to generate an image. Image from a given string. There is no encoding included, so you can define the encoding for the generated image by yourself. You can use a ttf font, which should be loaded into the options as []byte. If you not provide own fonts the gomono font golang.org/x/image/font/gofont/gomono will be used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Draw

func Draw(lines []string, opt *Options) (image.Image, error)

Draw takes a string and generates an image.Image from the text. If you are ok with the default Options you can pass nil for *Options.

// call with default options
img, err := timg.Draw(txt, nil)

func Wrap added in v0.10.1

func Wrap(s string, maxCharacters int) []string

Wrap generates the lines as a slice, which can be used inside timg.Draw().

img, err := timg.Draw(timg.Wrap(longString, 40), nil)
// ...

When creating the lines the words are separated.

Types

type Box

type Box struct {
	Top, Right, Bottom, Left int
}

Box defines int values for Top, Right, Bottom, Left a little bit similar like in CSS.

type Options

type Options struct {
	Padding   Box // absolute padding of the image
	Width     int // width of the image
	TType     truetype.Options
	Tpad      int // padding for the line height
	FontColor color.NRGBA
	Font      []byte // TTF font
}

Options which let you configure Draw()

func Default

func Default() *Options

Default returns the default options for Draw(). If you want to change some of the default values, you call this function and change just that values.

opt := timg.Default()
opt.Width = 5000
img, err := timg.Draw(txt, opt)

It is recomended to get always the default options, because that will decouple your code from that options. When some other options are added in later versions you will get them automatically.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL