identicon

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 License: MIT Imports: 6 Imported by: 0

README

Identicon Generator

Introduction

This is a small example of a simple identicon generator written in golang, the blog post can be found here: https://www.bartfokker.nl/posts/identicon/

go get to get the package

go get github.com/lercher/identicon

This Fork

This fork introduces more control over the png image generated, adds more contrast to the chosen color and publishes its list of set pixel coordinates.

Breaking Changes

The Name field is removed, b/c it is only converted to a string from the generator byte slice, which needs not be a string up-front.

The WriteImage method was removed and replaced by WritePNGImage with more parameters.

Added API

An identicon now publishes a slice of (X,Y) coordinates of set pixels as Pixels

Usage

import "github.com/lercher/identicon"

i := identicon.Generate([]byte("Simpson"))
// 50px per identicon pixel, i.e. 250x250 image written
// using dark colors in the byte range 0-127:
_ = i.WritePNGImage(w, 50, identicon.LightBackground(true))
log.Println(i.Pixels)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Identicon

type Identicon struct {
	Pixels []Point
	// contains filtered or unexported fields
}

Identicon grphically represents a hash in a 5x5 matrix

func Generate

func Generate(input []byte) Identicon

Generate creates an Identicon from an arbitrary byte array. It is garanteed that the same byte array produces the same Identicon.

func (Identicon) WritePNGImage

func (i Identicon) WritePNGImage(w io.Writer, pixwidth int, lbg LightBackground) error

WritePNGImage writes the identicon image to the given writer with width and height of 5 times pixwidth and LightBackground(true) or LightBackground(false) as lbg

type LightBackground

type LightBackground bool

LightBackground is either true or false

type Point

type Point struct {
	X, Y int
}

Point is 2d int/F5 coordinates

Directories

Path Synopsis
cmd
api
cli

Jump to

Keyboard shortcuts

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