identicon

package module
v0.0.0-...-a5b7d5f Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2018 License: BSD-2-Clause Imports: 9 Imported by: 0

README

Identicons in Golang

A kinda customizeable identicon implementation based on Bitmessage qidenticon

Sample icons

Sample icons

Example

Basic
package main

import (
	"image/png"
	"os"

	"github.com/fivenp/go-identicon"
)

func main() {
	code := identicon.Code("test")
	size := 30
	settings := identicon.DefaultSettings()
	img := identicon.Render(code, size, settings)
	w, err := os.Create("test.png")
	if err != nil {
		panic(err)
	}
	defer w.Close()
	err = png.Encode(w, img)
	if err != nil {
		panic(err)
	}
}
Advanced

Check the demo folder...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBackgroundColor = "#2d3e50"
View Source
var DefaultColorPalette = []Color{
	{Name: "lightBlack", Code: "#2c2c2c"},
	{Name: "lightBlackIntense", Code: "#232323"},
	{Name: "turquoise", Code: "#00bf93"},
	{Name: "turquoiseIntense", Code: "#16a086"},
	{Name: "mint", Code: "#2dcc70"},
	{Name: "mintIntense", Code: "#27ae61"},
	{Name: "green", Code: "#42e453"},
	{Name: "greenIntense", Code: "#24c333"},
	{Name: "yellow", Code: "#ffff25"},
	{Name: "yellowIntense", Code: "#d9d921"},
	{Name: "yellowOrange", Code: "#f1c40f"},
	{Name: "yellowOrangeIntense", Code: "#f39c11"},
	{Name: "brown", Code: "#e67f22"},
	{Name: "brownIntense", Code: "#d25400"},
	{Name: "orange", Code: "#ff944e"},
	{Name: "orangeIntense", Code: "#ff5500"},
	{Name: "red", Code: "#e84c3d"},
	{Name: "redIntense", Code: "#c1392b"},
	{Name: "blue", Code: "#3598db"},
	{Name: "blueIntense", Code: "#297fb8"},
	{Name: "darkBlue", Code: "#34495e"},
	{Name: "darkBlueIntense", Code: "#2d3e50"},
	{Name: "lightGrey", Code: "#ecf0f1"},
	{Name: "lightGreyIntense", Code: "#bec3c7"},
	{Name: "grey", Code: "#95a5a5"},
	{Name: "greyIntense", Code: "#7e8c8d"},
	{Name: "magenta", Code: "#ef3e96"},
	{Name: "magentaIntense", Code: "#e52383"},
	{Name: "violet", Code: "#df21b9"},
	{Name: "violetIntense", Code: "#be127e"},
	{Name: "purple", Code: "#9a59b5"},
	{Name: "purpleIntense", Code: "#8d44ad"},
	{Name: "lightBlue", Code: "#7dc2d2"},
	{Name: "lightBlueIntense", Code: "#1cabbb"},
	{Name: "white", Code: "#ffffff"},
	{Name: "whiteIntense", Code: "#f3f5f7"},
	{Name: "black", Code: "#000000"},
}

Functions

func Code

func Code(str string) uint64

Code derives a code for use with Render.

func Render

func Render(code uint64, totalSize int, settings *Settings) image.Image

Render generates an identicon. code is a code derived by the Code function. totalSize specifies the total size in pixels. It is recommended that this is divisible by 3.

Types

type Color

type Color struct {
	Name string
	Code string
}

type Settings

type Settings struct {
	// TwoColor specifies if the identicon should be
	// generated using one or two colors.
	TwoColor bool

	// Alpha specifies the transparency of the generated identicon.
	Alpha uint8

	TransparentBackground bool
	ColorPalette          []Color
	BackgroundColors      []string
}

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings returns a Settings object with the recommended settings.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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