godenticon

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IdenticonDefaultOptions = IdenticonConfiguration{
	Size:      6,
	Square:    false,
	Border:    false,
	Vertical:  false,
	Invert:    false,
	Symmetric: false,
}
View Source
var ImageDefaultOptions = ImageConfiguration{
	Size:     "L",
	Save:     false,
	SaveDir:  default_save_directory(),
	Portrait: false,
	FG:       "6dff24",
	BG:       "0b2100",
}

Functions

This section is empty.

Types

type Identicon

type Identicon struct {
	IdenticonOptions IdenticonConfiguration
	ImageOptions     ImageConfiguration
	Text             string
	Hash             string
	Width, Height    int
	Matrix           [][]int
}

func (*Identicon) CheckConfiguration added in v0.2.0

func (i *Identicon) CheckConfiguration()

Checks both Identicon.IdenticonOptions & Identicon.ImageOptions altogether for errors (kind of an One-Time function call).

When both Identicon.IdenticonOptions & Identicon.ImageOptions were already set by any means, then use this function directly instead of seperately calling Identicon.IdenticonOptions.CheckConfiguration() and Identicon.ImageOptions.CheckConfiguration(), to check for errors.

i.e.: Identicon.CheckConfiguration()

func (*Identicon) GenerateHash

func (i *Identicon) GenerateHash()

func (*Identicon) GenerateMatrix

func (i *Identicon) GenerateMatrix()

func (*Identicon) Print

func (i *Identicon) Print()

func (*Identicon) ReadConfiguration added in v0.2.0

func (i *Identicon) ReadConfiguration(path string)

Read, Check & Set configurations from a JSON config file. Sets both Identicon.IdenticonOptions & Identicon.ImageOptions requires: absolute/relative path of the JSON file.

func (*Identicon) UseDefaultConfiguration

func (i *Identicon) UseDefaultConfiguration()

Sets Identicon.IdenticonOptions & Identicon.ImageOptions using default values specified as variables - IdenticonDefaultOptions & ImageDefaultOptions for identicon & image respectively.

type IdenticonConfiguration

type IdenticonConfiguration struct {
	Size      int  `json:"size"`      // sets size of the identicon (range: 4-8)
	Square    bool `json:"square"`    // creates a square identicon
	Border    bool `json:"border"`    // adds a border to the identicon
	Vertical  bool `json:"vertical"`  // creates identicon in portrait dimension (not visible on using --square flag)
	Invert    bool `json:"invert"`    // inverts the cell filling of identicon
	Symmetric bool `json:"symmetric"` // creates symmetric identicon
}

func (*IdenticonConfiguration) CheckConfiguration

func (o *IdenticonConfiguration) CheckConfiguration()

Checks Identicon.IdenticonOptions for errors

type IdenticonIF

type IdenticonIF interface {
	// Sets Identicon.IdenticonOptions & Identicon.ImageOptions
	// using default values specified as variables -
	// IdenticonDefaultOptions & ImageDefaultOptions for
	// identicon & image respectively.
	UseDefaultConfiguration()

	// Read, Check & Set configurations from a JSON config file.
	// Sets both Identicon.IdenticonOptions & Identicon.ImageOptions
	// requires: absolute/relative path of the JSON file.
	ReadConfiguration(path string)

	// Check for errors in configurations.
	// Applies to IdenticonConfiguration, ImageConfiguration
	// and Identicon types.
	CheckConfiguration()

	// Sets Identicon.Hash, Indenticon.Width & Identicon.Height
	// based on Identicon.IdenticonOptions.Square (bool).
	//
	// if: Identicon.IdenticonOptions.Square == TRUE, then
	// generate(set) Identicon.Hash suitable for square (1:1) aspect ratios
	// and set Identicon.Width, Identicon.Height = 1, 1
	// else:
	// generate(set) Identicon.Hash suitable for wide (2:1) aspect ratios
	// and set Identicon.Width, Identicon.Height = 2, 1
	GenerateHash()

	// Sets Identicon.Matrix based on some Identicon.IdenticonOptions.
	// Uses IdenticonConfiguration.Vertical (bool), IdenticonConfiguration.Invert (bool)
	// & IdenticonConfiguration.Symmetric (bool) to generate 8 different types of
	// matrices.
	//
	// Combinations:
	// vertical-inverted-symmetric, vertical-inverted-asymmetric, vertical-original-symmetric
	// vertical-original-asymmetric, horizontal-inverted-symmetric, horizontal-inverted-asymmetric
	// horizontal-original-symmetric, horizontal-original-asymmetric
	GenerateMatrix()

	// Printing the Identicon.Matrix to the terminal.
	// Identicon.IdenticonOptions.Border (bool) is used to determine whether
	// to print the identicon with/without border.
	Print()
}

type ImageConfiguration

type ImageConfiguration struct {
	Size     string `json:"image-size"`     // saves image with given resolution preset (S,M,L,X)
	Save     bool   `json:"save"`           // save the identicon as an image with default image options
	SaveDir  string `json:"save-dir"`       // saves image to the specified directory
	Portrait bool   `json:"image-portrait"` // saves image with portrait dimensions
	FG       string `json:"fg"`             // sets image's foreground color
	BG       string `json:"bg"`             // sets image's background color
}

func (*ImageConfiguration) CheckConfiguration

func (o *ImageConfiguration) CheckConfiguration()

Checks Identicon.ImageOptions for errors

Jump to

Keyboard shortcuts

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