avatar

package
v0.0.0-...-7abac79 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSizeArg = errors.New("invalid size name")

Functions

func SvgForAvatar

func SvgForAvatar(initials string, gradientHash uint, grayscale bool, faded bool, fontLoader avatarFontProvider) ([]byte, string, error)

Return the SVG XML body for the given initials, the content-type and an error

Types

type Initials

type Initials interface {
	// Generate will create a new avatar with the given initials and color.
	Generate(initials, color string) ([]byte, error)
	ContentType() string
}

Initials is able to generate initial avatar.

type Options

type Options int

Options can be used to give options for the generated image

const (
	GreyBackground Options = 1 + iota
	Translucent    Options = 1 + iota
	FormatPNG      Options = 1 + iota // If this option is absent, SVG is assumed
	EmbedFont      Options = 1 + iota
)

type PNGInitials

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

PNGInitials create PNG avatars with initials in it.

This implementation is based on the `convert` binary.

func NewPNGInitials

func NewPNGInitials(cmd string) *PNGInitials

NewPNGInitials instantiate a new PNGInitials.

func (*PNGInitials) ContentType

func (a *PNGInitials) ContentType() string

ContentType return the generated avatar content-type.

func (*PNGInitials) Generate

func (a *PNGInitials) Generate(initials, color string) ([]byte, error)

Generate will create a new avatar with the given initials and color.

type Service

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

Service handle all the interactions with the initials images.

func NewService

func NewService(cache cache.Cache, cmd string) *Service

NewService instantiate a new Service.

func (*Service) GenerateInitials

func (s *Service) GenerateInitials(publicName string, fontLoader avatarFontProvider, opts ...Options) ([]byte, string, error)

GenerateInitials an image with the initials for the given name (and the content-type to use for the HTTP response).

Jump to

Keyboard shortcuts

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