Base class for identiconpp.
More...
#include <identiconpp.hpp>
|
| 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< 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...
|
|
const string | generate_base64 (const string &magick, const string &digest, const uint16_t width=100) |
| Generates identicon from digest. More...
|
|
Base class for identiconpp.
Use this class for all your identicons. Exceptions will be thrown on error.
- Examples:
- example.cpp.
◆ algorithm
List of identicon algorithms.
Enumerator |
---|
ltr_symmetric | Generates symmetric (vertically mirrored) identicons.
|
ltr_asymmetric | Generates asymmetric identicons.
|
sigil | Generates the same results as sigil and pydenticon.
|
◆ 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< 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
-
columns | Number of columns |
rows | Number of rows |
type | The algorithm to use |
background | Background color, hexadecimal, rrggbbaa |
foreground | vector of foreground colors |
padding | Padding in pixels { left & right, top & down } |
- Since
- before 0.5.0
33 , _background(background)
34 , _foreground(foreground)
37 check_color(_background);
39 for (
const string &color : _foreground)
44 if (_foreground.size() == 0)
46 throw std::invalid_argument
48 "You must specify at least 1 foreground color."
◆ generate()
Magick::Image Identiconpp::generate |
( |
const string & |
digest, |
|
|
const uint16_t |
width = 100 |
|
) |
| |
Generates identicon from digest.
- Parameters
-
digest | The pre-computed digest |
width | The width of the image in pixels |
- Returns
- The image as Magick::Image
- Since
- before 0.5.0
- Examples:
- example.cpp.
55 ttdebug <<
"Using digest: " << digest <<
'\n';
56 check_entropy(digest, _type);
57 const std::int16_t imgwidth = width - _padding[0] * 2;
58 const std::int16_t imgheight =
59 std::round(static_cast<float>(imgwidth) / _columns * _rows);
60 ttdebug <<
"width: " << std::to_string(imgwidth)
61 <<
"+" << std::to_string(_padding[0] * 2)
62 <<
", height: " << std::to_string(imgheight)
63 <<
"+" << std::to_string(_padding[1] * 2)
65 if (imgwidth <= 0 || imgheight <= 0)
67 throw std::invalid_argument(
"Width or height is zero or less.");
75 img = generate_ltr_symmetric(digest);
80 img = generate_ltr_asymmetric(digest);
85 img = generate_sigil(digest);
90 img.scale(Magick::Geometry(imgwidth, imgheight));
93 img.compose(Magick::CompositeOperator::CopyCompositeOp);
94 img.matteColor(Magick::Color(
'#' + _background));
95 img.frame(Magick::Geometry(_padding[0], _padding[1]));
Generates symmetric (vertically mirrored) identicons.
Generates asymmetric identicons.
◆ generate_base64()
const string Identiconpp::generate_base64 |
( |
const string & |
magick, |
|
|
const string & |
digest, |
|
|
const uint16_t |
width = 100 |
|
) |
| |
Generates identicon from digest.
- Parameters
-
- Returns
- The image as base64-string
- Since
- 0.5.0
103 Magick::Image img =
generate(digest, width);
107 return blob.base64();
Magick::Image generate(const string &digest, const uint16_t width=100)
Generates identicon from digest.
Definition: identiconpp.cpp:53
The documentation for this class was generated from the following files:
- src/identiconpp.hpp
- src/checks.cpp
- src/identiconpp.cpp
- src/ltr_asymmetric.cpp
- src/ltr_symmetric.cpp
- src/sigil.cpp