identiconpp  0.3.1
Public Types | Public Member Functions | List of all members
Identiconpp Class Reference

Base class for identiconpp. More...

#include <identiconpp.hpp>

Public Types

enum  algorithm { ltr_symmetric, ltr_asymmetric, sigil }
 List of identicon algorithms.
 

Public Member Functions

 Identiconpp (const uint8_t columns, const uint8_t rows, algorithm type=algorithm::ltr_symmetric, const string &background="ffffffff", const vector< string > &foreground={ "000000ff" }, const array< const uint8_t, 2 > &padding={ 0, 0 })
 Initialises an instance of Identiconpp. More...
 
Magick::Image generate (const string &digest, const uint16_t width=100)
 Generates identicon from digest. More...
 

Detailed Description

Base class for identiconpp.

Use this class for all your identicons. Exceptions will be thrown on error.

Constructor & Destructor Documentation

◆ Identiconpp()

Identiconpp::Identiconpp ( const uint8_t  columns,
const uint8_t  rows,
algorithm  type = algorithm::ltr_symmetric,
const string &  background = "ffffffff",
const vector< string > &  foreground = { "000000ff" },
const array< const uint8_t, 2 > &  padding = { 0, 0 } 
)
explicit

Initialises an instance of Identiconpp.

The instance can be used for creating identicons with differing image formats and sizes. The colors must consist of exactly 8 digits.

Parameters
columnsNumber of columns
rowsNumber of rows
typeThe algorithm to use
backgroundBackground color, hexadecimal, rrggbbaa
foregroundvector of foreground colors
paddingPadding in pixels { left & right, top & down }
28 : _rows(rows)
29 , _columns(columns)
30 , _type(type)
31 , _background(background)
32 , _foreground(foreground)
33 , _padding(padding)
34 {
35  check_color(background);
36 
37  for (const string &color : foreground)
38  {
39  check_color(color);
40  }
41 }

Member Function Documentation

◆ generate()

Magick::Image Identiconpp::generate ( const string &  digest,
const uint16_t  width = 100 
)

Generates identicon from digest.

Parameters
digestThe pre-computed digest
widthThe width of the image in pixels
Returns
The image as Magick::Image
44 {
45  ttdebug << "Using digest: " << digest << '\n';
46  check_entropy(digest, _type);
47  const uint16_t imgwidth = width - _padding[0] * 2;
48  const uint16_t imgheight = imgwidth / _columns * _rows;
49  ttdebug << "width: " << std::to_string(imgwidth + _padding[0] * 2)
50  << ", height: " << std::to_string(imgheight + _padding[1] * 2)
51  << "\n";
52  Magick::Image img;
53 
54  switch (_type)
55  {
56  case algorithm::ltr_symmetric:
57  {
58  img = generate_ltr_symmetric(digest);
59  break;
60  }
61  case algorithm::ltr_asymmetric:
62  {
63  img = generate_ltr_asymmetric(digest);
64  break;
65  }
66  case algorithm::sigil:
67  {
68  img = generate_sigil(digest);
69  break;
70  }
71  }
72 
73  img.backgroundColor(Magick::Color('#' + _background));
74  img.scale(Magick::Geometry(imgwidth, imgheight));
75  img.borderColor(Magick::Color('#' + _background));
76  img.border(Magick::Geometry(_padding[0], _padding[1]));
77  return img;
78 }

The documentation for this class was generated from the following files: