A Go library for Identicon generation
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
.gitignore
.travis.yml
LICENSE
README.md
identicon-banner.png
identicon.go
identicon_test.go

README.md

Identicon

A Go library for Identicon generation

Godoc Build Status Go Report Card codecov

This Go library helps generating deterministic Identicons, like these:

Example Banner

Installation

go get github.com/tsdtsdtsd/identicon

Usage example

Basically, you construct a new Identicon type with identicon.New(), giving it your identification string and some optional identicon.Options. The resulting struct implements image.Image and draw.Image, so you can use it flexibly.

Just import the library and create a new identicon:

package main

import (
    "log"
    "github.com/tsdtsdtsd/identicon"
) 

func main() {
    
    ic, err := identicon.New(
        
        // The identicon ID string is mandatory.
	// Same string will always result in the same generated identicon.
	// Typically this is a username or email address.
        "identicon",
        
	// You can define custom options or pass nil for defaults
	&identicon.Options{
	    BackgroundColor: identicon.RGB(240, 240, 240),
	},
    )
    
    if err != nil {
	log.Fatal(err)
    }
    
    // Now you are free to use identicon `ic` as any other image.Image or draw.Image interface
    fi, _ := os.Create("my-file.png")
    png.Encode(fi, ic)
}

Banner example

You can find another example in the /example folder. It contains an application, which generates the above image. It also helps me to test the algorythm for changes.