avatarbuilder

package module
v0.0.0-...-4522dfd Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2018 License: MIT Imports: 11 Imported by: 0

README

avatarbuilder

Using go freetype to build default avatar with string

number text english text chinese text

Install

go get -u github.com/ShiningRush/avatarbuilder

Usage

You can referrence ./example

Some snipet is as blow

  // init avatarbuilder, you need to tell builder ttf file and how to alignment text
	ab := avatarbuilder.NewAvatarBuilder("./SourceHanSansSC-Medium.ttf", &calc.SourceHansSansSCMedium{})
	ab.SetBackgroundColorHex(colors[1])
	ab.SetFrontgroundColor(color.White)
	ab.SetFontSize(80)
	ab.SetAvatarSize(200, 200)
	if err := ab.GenerateImageAndSave("12", "./out.png"); err != nil {
		fmt.Println(err)
		return
	}

Extend Other Font

Because element of width of each font is different, so you need tell avatar how to align the content. Avatar already implement a free font(made by google and adobe)'s center algorithm in ./calc, If you need other font, feel free to PR or issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AvatarBuilder

type AvatarBuilder struct {
	W int
	H int
	// contains filtered or unexported fields
}

func NewAvatarBuilder

func NewAvatarBuilder(fontfile string, calc FontCenterCalculator) *AvatarBuilder

func (*AvatarBuilder) GenerateImage

func (ab *AvatarBuilder) GenerateImage(s string) ([]byte, error)

func (*AvatarBuilder) GenerateImageAndSave

func (ab *AvatarBuilder) GenerateImageAndSave(s string, outname string) error

func (*AvatarBuilder) GetFontWidth

func (ab *AvatarBuilder) GetFontWidth() int

func (*AvatarBuilder) SetAvatarSize

func (ab *AvatarBuilder) SetAvatarSize(w int, h int)

func (*AvatarBuilder) SetBackgroundColor

func (ab *AvatarBuilder) SetBackgroundColor(c color.Color)

func (*AvatarBuilder) SetBackgroundColorHex

func (ab *AvatarBuilder) SetBackgroundColorHex(hex uint32)

func (*AvatarBuilder) SetFontSize

func (ab *AvatarBuilder) SetFontSize(size float64)

func (*AvatarBuilder) SetFrontgroundColor

func (ab *AvatarBuilder) SetFrontgroundColor(c color.Color)

func (*AvatarBuilder) SetFrontgroundColorHex

func (ab *AvatarBuilder) SetFrontgroundColorHex(hex uint32)

type FontCenterCalculator

type FontCenterCalculator interface {
	// CalculateCenterLocation used to calculate center location in different font style
	CalculateCenterLocation(string, *AvatarBuilder) (int, int)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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