avatar

package module
v0.0.0-...-0f7b16e Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2017 License: MIT Imports: 17 Imported by: 0

README

Avatar: Generate Avatars for the web

Build Status Go Report Card Coverage Status GoDoc

Avatar is a package that allows you to create avatars for pictures and initials.

You can create square avatars, or round avatars.

Picture:

    size := 200

    fileBytes, _ := ioutil.ReadFile("./test_data/super_mascot.jpg")
    newAvatar, _ := NewAvatarFromPic(fileBytes, &PictureOptions{
        Size: size, // default 300
    })

    round, err := newAvatar.Circle()
    roundFile, _ := os.Create("./output/round_super_mascot.png")
    roundFile.Write(round)

    square, err := newAvatar.Square()
    squareFile, _ := os.Create("./output/square_super_mascot.png")
    roundFile.Write(square)

Initials:

    size := 200
    newAvatar, err := NewAvatarFromInitials([]byte("John Smith"), &InitialsOptions{
        FontPath:  "./test_data/Arial.ttf",    // Required
        Size:      size,                       // default 300
        NInitials: 2,                          // default 1 - If 0, the whole text will be printed
        TextColor: color.White,                // Default White
        BgColor:   color.RGBA{0, 0, 255, 255}, // Default color.RGBA{215, 0, 255, 255} (purple)
    })

    square, _ := newAvatar.Square()
    squareFile, _ := os.Create("./output/square_john_smith_initials.png")
    defer squareFile.Close()
    squareFile.Write(square)

    round, _ := newAvatar.Circle()
    roundFile, _ := os.Create("./output/round_john_smith_initials.png")
    defer roundFile.Close()
    roundFile.Write(round)

The input for initials can be any text, and the package identifies the best candidates for the initials.

If you give it an email address, it will try to identify the initials in the string preceding the @.

Not specifying NInitials in options would print the whole text as is.

And the font path is required, so maybe it should not be put in InitialsOptions, we'll see what the community thinks.

What you get:

From our original picture:

Our outputs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Avatar

type Avatar interface {
	Source() []byte          // get source content for avatar generation
	Square() ([]byte, error) // generates the square avatar
	Circle() ([]byte, error) // generates the round avatar
	// contains filtered or unexported methods
}

type AvatarOptions

type AvatarOptions interface {
	// contains filtered or unexported methods
}

type Circle

type Circle struct {
	// contains filtered or unexported fields
}

func (*Circle) At

func (c *Circle) At(x, y int) color.Color

func (*Circle) Bounds

func (c *Circle) Bounds() image.Rectangle

func (*Circle) ColorModel

func (c *Circle) ColorModel() color.Model

type Initials

type Initials struct {
	// contains filtered or unexported fields
}

func NewAvatarFromInitials

func NewAvatarFromInitials(text []byte, options *InitialsOptions) (*Initials, error)

func (Initials) Circle

func (i Initials) Circle() ([]byte, error)

func (Initials) Source

func (i Initials) Source() []byte

func (Initials) Square

func (i Initials) Square() ([]byte, error)

Generates the square avatar It returns the avatar image in []byte or an error something went wrong

type InitialsOptions

type InitialsOptions struct {
	BgColor   color.Color
	Size      int
	FontPath  string
	TextColor color.Color
	NInitials int
}

type Picture

type Picture struct {
	// contains filtered or unexported fields
}

func NewAvatarFromPic

func NewAvatarFromPic(pic []byte, options *PictureOptions) (*Picture, error)

func (Picture) Circle

func (p Picture) Circle() ([]byte, error)

func (Picture) Source

func (p Picture) Source() []byte

func (Picture) Square

func (p Picture) Square() ([]byte, error)

Generates the square avatar It returns the avatar image in []byte or an error something went wrong

type PictureOptions

type PictureOptions struct {
	BgColor color.Color
	Size    int
}

Jump to

Keyboard shortcuts

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