Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Identicon

A Go library for Identicon generation

Latest Release Version Godoc Build Status Go Report Card codecov

This Go library helps to generate deterministic Identicons from strings, like these:

Example Banner

Installation

With module support, you can just import github.com/tsdtsdtsd/identicon.

In other cases you may have to manually:

go get -u 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 (
    "image/png"
    "log"
    "os"
    
    "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.
        "my-identicon@example.com",
        
        // 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.

About

A Go library for Identicon generation

Resources

License

Packages

No packages published

Languages