Documentation
¶
Overview ¶
Package tinyicons is a tiny package to generate icons from a user string (such as an email address or username). Similar in principal to gravatar but with a focus on a tiny, fast, and simple implementation and tiny png images.
Icons are generated from a 32-bit FNV-1a hash of the input value, which bits determines a 7x7 pattern. The most significant 4 bits determine the foreground color from a pre-defined color palette. The 7 rows of the icon are determined from 4-bit sequences starting at the LSB. Bits 0,1,2,3 are used to determine if the foreground color is set in the 7-pixel-wide row using the pattern: [3210123].
When encoded as a PNG image, a 1-pixel background-color border is added, and all pixels are scaled by ScaleFactor, so the 7x7 pattern becomes (9x9)x4 = 36x36 pixels.
The Icon can thus be packed into a 8-character hex string to allow easy referencing without the original string.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Palette = []color.RGBA{
{R: 204, G: 102, B: 119, A: 255},
{R: 51, G: 34, B: 136, A: 255},
{R: 51, G: 187, B: 238, A: 255},
{R: 17, G: 119, B: 51, A: 255},
{R: 136, G: 34, B: 85, A: 255},
{R: 68, G: 170, B: 153, A: 255},
{R: 153, G: 153, B: 51, A: 255},
{R: 170, G: 68, B: 153, A: 255},
{R: 221, G: 221, B: 221, A: 255},
}
var (
// ScaleFactor scales the 9x9 icon image by this factor in PNG output.
ScaleFactor = 4
)
Functions ¶
This section is empty.
Types ¶
type Icon ¶
type Icon uint32
Icon is a 7x7 icon with horizontal symmetry, packed into 32 bits.
func (Icon) DrawPNG ¶
DrawPNG writes a PNG image of the 7x7 Icon, with a 1px borders, scaled by ScaleFactor, to the io.Writer provided.