identiconpp is a library to generate identicons for C++.
Aller au fichier
tastytea 34eedfe6d1
continuous-integration/drone/push Build is passing Détails
Fix rpm package generation.
* Set CXX for CentOS in CI correctly.
* Install the right ImageMagick.
* Fix gpg call.
* Fixed signature path.
2019-07-30 14:50:37 +02:00
src Whitesapace cleanup. 2019-07-30 13:07:45 +02:00
tests Moved tests. 2019-07-30 11:32:34 +02:00
.drone.yml Fix rpm package generation. 2019-07-30 14:50:37 +02:00
.gitignore Initial commit 2018-12-25 21:26:51 +01:00
CMakeLists.txt Version bump 0.6.1. 2019-07-30 13:51:58 +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.md Updated readme. 2019-07-30 13:41:16 +02:00
build_doc.sh Simplyfied doxygen config. 2019-07-30 11:33:35 +02:00
example.c Added pkg-config file. 2019-07-30 13:04:08 +02:00
example.cpp Added pkg-config file. 2019-07-30 13:04:08 +02:00
identiconpp.pc.in Added pkg-config file. 2019-07-30 13:04:08 +02:00
identiconpp_c.pc.in Added pkg-config file. 2019-07-30 13:04:08 +02:00
packages.CMakeLists.txt Updated and modularized cmake recipes. 2019-07-30 11:32:57 +02:00

README.md

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

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

The example images above are generated using [example.cpp] (https://schlomp.space/tastytea/identiconpp/src/branch/master/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/] (https://doc.schlomp.space/identiconpp/classIdenticonpp.html).

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;
}

C interface

This is somewhat experimental. Have a look at [example.c] (https://schlomp.space/tastytea/identiconpp/src/branch/master/example.c) and identiconpp_c.h.

It seems to be impossible to use Magick++ and MagickWand in the same library, so the images are returned as base64-encoded strings.

Install

Gentoo

Gentoo ebuilds are available via my repository.

Automatically generated packages

Binary packages are generated automatically for each release in the formats deb and rpm. 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 ..
make
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, execute make package

Contributing

Contributions are always welcome. You can submit them as pull requests on schlomp.space or via email to tastytea@tastytea.de (ideally using git format-patch or git send-email). Please do not submit them via GitHub, it is just a mirror.

Contact

See https://tastytea.de/

Copyright © 2018 tastytea <tastytea@tastytea.de>.
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.

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] (https://schlomp.space/tastytea/identiconpp/src/branch/master/src/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] (https://schlomp.space/tastytea/identiconpp/src/branch/master/src/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] (https://schlomp.space/tastytea/identiconpp/src/branch/master/src/sigil.cpp)