Identicons in Go
After checking with the official docker golang container releases, I can say with some confidence
idicon
works with golang versions 1.2+.
go get github.com/GeorgeMac/idicon/cmd/idicon
See: idicon command for command usage.
Basically this:
generator, err := icon.NewGenerator(5, 5)
if err != nil {
// handle error
}
// use the generator for a given string input
icn := generator.Generate(`GeorgeMac`)
// print svg string representation
fmt.Print(icn)
NewGenerator produces a idicon icon generator struct for producing *icon.Icon
It takes a width, height and an variadic set of options.
type option func(g *Generator) error
func NewGenerator(width, height int, options ...option) *Generator { ... }
Current available options include:
icon.UseHash(h hash.Hash) // Defaults to crypto.Sha1.New
icon.LinearDistribution // Different way of indexing flipped bits
icon.With(props icon.Props) // SVG output properties
type Props struct {
BaseColour *colour.Colour
Palette colour.Palette
Size int
Padding int
BorderRadius int
}
- BaseColour - background colour
- Palette - colour palette for deriving svg square colours
- Size - width/height of an individual svg square
- Padding - padding around the svg grid of squares
- BorderRadius - for those pretty curved corners