identiconpp is a library to generate identicons for C++.
Go to file
tastytea 9070f154a4
continuous-integration/drone/push Build is passing Details
Version bump 0.7.3.
2020-10-24 11:30:43 +02:00
cmake Modernized CMake recipes and moved files around. 2019-09-13 18:45:30 +02:00
examples Modernized CMake recipes and moved files around. 2019-09-13 18:45:30 +02:00
include Install header. 2019-09-23 19:00:52 +02:00
pkg-config Modernized CMake recipes and moved files around. 2019-09-13 18:45:30 +02:00
src Added include dir for BUILD_INTERFACE. 2019-09-13 18:57:48 +02:00
tests Remove C support. 2019-09-13 16:45:40 +02:00
.drone.yml Generate package for Debian buster. 2020-10-24 11:29:50 +02:00
.editorconfig Update editorconfig. 2020-10-24 09:44:56 +02:00
.gitignore Initial commit 2018-12-25 21:26:51 +01:00
CMakeLists.txt Version bump 0.7.3. 2020-10-24 11:30:43 +02:00
CODE_OF_CONDUCT.adoc Fix coc contact. 2019-09-27 04:08:20 +02:00
CONTRIBUTING.adoc Make more use of variables in contribution guidelines. 2019-09-27 04:09:08 +02:00
Doxyfile Simplyfied doxygen config. 2019-07-30 11:33:35 +02:00
LICENSE Initial commit 2018-12-25 21:26:51 +01:00
README.adoc Generate package for Debian buster. 2020-10-24 11:29:50 +02:00
build_doc.sh Simplyfied doxygen config. 2019-07-30 11:33:35 +02:00
packages.CMakeLists.txt Fix Debian package generation. 2020-10-24 10:14:45 +02:00

README.adoc

identiconpp

identiconpp is a library to generate identicons for C++.

You get the images as Magick::Image. This allows you to make all kinds of modifications.

Example 1. Used algorithms, left to right: 4x4 ltr_symmetric, 20px padding; 5x5 sigil; 5x5 ltr_asymmetric; 6x4 ltr_symmetric, 10px padding

identicon1 identicon2 identicon3 identicon4

The example images above are generated using example.cpp.

Features

  • ✓ Symmetric identicons

  • ✓ sigil identicons

  • ✓ Asymmetric identicons

  • ✓ Padding

Usage

The HTML reference can be generated with build_doc.sh, if doxygen is installed. It is also available at doc.schlomp.space/identiconpp/.

You need to generate hashes yourself, any hexadecimal string will do. Make sure to use a safe hashing algorithm for sensitive data (not MD5). You can select as many columns and rows as you like, but make sure you have enough entropy. If something seems to be wrong, exceptions will be thrown.

The "sigil" algorithm generates the same results as sigil and pydenticon.

Example

// Compile with g++ $(pkg-config --libs --cflags identiconpp)
#include <iostream>
#include <identiconpp.hpp>
#include <Magick++/Image.h>

int main()
{
    Identiconpp identicon(5, 5, Identiconpp::algorithm::ltr_symmetric,
                          "ffffff80", { "800000ff" }, { 10, 10 });
    Magick::Image img;
    img = identicon.generate("55502f40dc8b7c769880b10874abc9d0", 200);
    img.write("identicon.png");

    std::cout << identicon.generate_base64("png", "5550", 200) << std::endl;
}

Install

Gentoo

Gentoo ebuilds are available via my repository.

Automatically generated packages

Binary packages are generated automatically for each release. They are signed with my automatic signing key.

From source

Dependencies

On a Debian system, install the packages: build-essential cmake libmagick++-dev.

Compile

mkdir build
cd build
cmake ..
cmake --build .
make install
cmake options:
  • -DCMAKE_BUILD_TYPE=Debug for a debug build

  • -DWITH_TESTS=YES to build tests

  • One of:

    • -DWITH_DEB=YES to generate a deb-package

    • -DWITH_RPM=YES to generate an rpm-package

To generate a binary package, run make package.

Algorithms

ltr_symmetric

  • Create image with width=columns, height=rows.

  • Set background color.

  • Select half of the columns, or half of the columns + 1 if uneven.

    • columns / 2 + columns % 2

  • Pixels are drawn from left to right, top to bottom.

  • Use bits from digest to determine if a pixel is painted(1) or not(0).

  • Mirror the pixels vertically.

  • Use the following bits to pick the foreground color.

    • You need floor(log2(n_colors)) + 1 bits.

  • Scale image proportionally to requested width.

 0111 0011 1101 1100 […] 1111 0111 0101 0111
^                            ^
+----------------------------+-------------->
             |                      |
        pixel matrix        foreground color

Implemented in ltr_symmetric.cpp.

ltr_asymmetric

  • Create image with width=columns, height=rows.

  • Set background color.

  • Pixels are drawn from left to right, top to bottom.

  • Use bits from digest to determine if a pixel is painted(1) or not(0).

  • Use the following bits to pick the foreground color.

    • You need floor(log2(n_colors)) + 1 bits.

  • Scale image proportionally to requested width.

 0111 0011 1101 1100 […] 1111 0111 0101 0111
^                            ^
+----------------------------+-------------->
             |                      |
        pixel matrix        foreground color

Implemented in ltr_asymmetric.cpp.

sigil

  • Create image with width=columns, height=rows.

  • Set background color.

  • Select half of the columns, or half of the columns + 1 if uneven.

    • columns / 2 + columns % 2

  • Pixels are drawn from top to bottom, left to right.

  • Use the first 8 bits to pick the foreground color.

  • Use the following bits to determine if a pixel is painted(1) or not(0).

  • Mirror the pixels vertically.

  • Scale image proportionally to requested width.

 0111 0011 1101 1100
^         ^
+---------+--------->
     |            |
foreground color  |
             pixel matrix

Implemented in sigil.cpp.