2019-09-27 07:16:03 +02:00
|
|
|
= identiconpp
|
|
|
|
:toc: preamble
|
|
|
|
|
|
|
|
:project: identiconpp
|
|
|
|
:uri-base: https://schlomp.space/tastytea/{project}
|
|
|
|
:uri-branch-master: {uri-base}/src/branch/master
|
|
|
|
:uri-reference-base: https://doc.schlomp.space/{project}
|
|
|
|
:uri-images-base: {uri-reference-base}
|
|
|
|
:uri-sigil: https://github.com/cupcake/sigil/
|
|
|
|
:uri-pydenticon: https://github.com/azaghal/pydenticon/
|
|
|
|
:uri-overlay: https://schlomp.space/tastytea/overlay
|
|
|
|
:uri-pgpkey: https://tastytea.de/tastytea_autosign.asc
|
|
|
|
:uri-gcc: https://gcc.gnu.org/
|
|
|
|
:uri-clang: https://clang.llvm.org/
|
|
|
|
:uri-cmake: https://cmake.org/
|
|
|
|
:uri-imagemagick: https://www.imagemagick.org/
|
|
|
|
:uri-asciidoc: http://asciidoc.org/
|
|
|
|
:uri-catch: https://github.com/catchorg/Catch2
|
|
|
|
|
|
|
|
*identiconpp* is a library to generate identicons for C++.
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2018-12-26 06:30:05 +01:00
|
|
|
You get the images as `Magick::Image`. This allows you to make all kinds of
|
|
|
|
modifications.
|
2018-12-26 03:26:53 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
.Used algorithms, left to right: 4x4 ltr_symmetric, 20px padding; 5x5 sigil; 5x5 ltr_asymmetric; 6x4 ltr_symmetric, 10px padding
|
|
|
|
====
|
|
|
|
image:{uri-images-base}/identicon1.png[]
|
|
|
|
image:{uri-images-base}/identicon2.png[]
|
|
|
|
image:{uri-images-base}/identicon3.png[]
|
|
|
|
image:{uri-images-base}/identicon4.png[]
|
2018-12-28 01:57:08 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
The example images above are generated using
|
|
|
|
link:{uri-branch-master}/examples/example.cpp[example.cpp].
|
|
|
|
====
|
2019-01-03 08:17:33 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
== Features
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2018-12-26 23:27:27 +01:00
|
|
|
* [x] Symmetric identicons
|
|
|
|
* [x] sigil identicons
|
2018-12-27 05:21:40 +01:00
|
|
|
* [x] Asymmetric identicons
|
2018-12-27 06:13:49 +01:00
|
|
|
* [x] Padding
|
2018-12-26 06:30:05 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
== Usage
|
2018-12-25 21:46:29 +01:00
|
|
|
|
2019-07-30 13:36:40 +02:00
|
|
|
The HTML reference can be generated with `build_doc.sh`, if doxygen is
|
2019-09-27 07:16:03 +02:00
|
|
|
installed. It is also available at
|
|
|
|
link:{uri-reference-base}/classIdenticonpp.html[doc.schlomp.space/identiconpp/].
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2018-12-26 23:27:27 +01:00
|
|
|
You need to generate hashes yourself, any hexadecimal string will do. Make sure
|
2019-09-27 07:16:03 +02:00
|
|
|
to use a safe hashing algorithm for sensitive data (*not MD5*). You can select
|
2018-12-26 23:27:27 +01:00
|
|
|
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.
|
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
The "sigil" algorithm generates the same results as link:{uri-sigil}[sigil] and
|
|
|
|
link:{uri-pydenticon}[pydenticon].
|
2018-12-28 01:57:08 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
=== Example
|
2018-12-26 06:30:05 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
[source,c++]
|
|
|
|
----
|
2019-07-30 12:48:11 +02:00
|
|
|
// Compile with g++ $(pkg-config --libs --cflags identiconpp)
|
2019-01-17 20:02:47 +01:00
|
|
|
#include <iostream>
|
2018-12-26 06:30:05 +01:00
|
|
|
#include <identiconpp.hpp>
|
|
|
|
#include <Magick++/Image.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2018-12-26 23:27:27 +01:00
|
|
|
Identiconpp identicon(5, 5, Identiconpp::algorithm::ltr_symmetric,
|
2018-12-27 06:33:19 +01:00
|
|
|
"ffffff80", { "800000ff" }, { 10, 10 });
|
2018-12-26 06:30:05 +01:00
|
|
|
Magick::Image img;
|
|
|
|
img = identicon.generate("55502f40dc8b7c769880b10874abc9d0", 200);
|
|
|
|
img.write("identicon.png");
|
2019-01-17 20:02:47 +01:00
|
|
|
|
|
|
|
std::cout << identicon.generate_base64("png", "5550", 200) << std::endl;
|
2018-12-26 06:30:05 +01:00
|
|
|
}
|
2019-09-27 07:16:03 +02:00
|
|
|
----
|
2018-12-26 06:30:05 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
== Install
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
=== Gentoo
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
Gentoo ebuilds are available via my link:{uri-overlay}[repository].
|
2018-12-26 06:30:05 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
=== Automatically generated packages
|
2018-12-26 06:30:05 +01:00
|
|
|
|
|
|
|
Binary packages are generated automatically for each
|
2020-10-24 10:26:12 +02:00
|
|
|
link:{uri-base}/releases[release] for Debian stretch. They are signed with my
|
|
|
|
link:{uri-pgpkey}[automatic signing key].
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
=== From source
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
==== Dependencies
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
* C++ compiler (tested: link:{uri-gcc}[gcc] 6/8/9, link:{uri-clang}[clang] 7)
|
|
|
|
* {uri-cmake}[cmake] (at least 3.6)
|
|
|
|
* link:{uri-imagemagick}[imagemagick] (tested: 7.0 / 6.7)
|
2019-01-01 16:46:17 +01:00
|
|
|
* Optional:
|
2019-09-27 07:16:03 +02:00
|
|
|
** Manpage: {uri-asciidoc}[asciidoc] (tested: 8.6)
|
|
|
|
** Tests: {uri-catch}[catch] (tested: 2.5 / 1.2)
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2018-12-26 06:30:05 +01:00
|
|
|
On a Debian system, install the packages:
|
|
|
|
`build-essential cmake libmagick++-dev`.
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
==== Compile
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
[source,shell]
|
|
|
|
----
|
2018-12-25 18:33:19 +01:00
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ..
|
2019-09-27 07:16:03 +02:00
|
|
|
cmake --build .
|
2018-12-25 18:33:19 +01:00
|
|
|
make install
|
2019-09-27 07:16:03 +02:00
|
|
|
----
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
.cmake options:
|
2018-12-25 18:33:19 +01:00
|
|
|
* `-DCMAKE_BUILD_TYPE=Debug` for a debug build
|
2019-01-02 06:57:46 +01:00
|
|
|
* `-DWITH_TESTS=YES` to build tests
|
2018-12-26 06:30:05 +01:00
|
|
|
* One of:
|
2019-09-27 07:16:03 +02:00
|
|
|
** `-DWITH_DEB=YES` to generate a deb-package
|
|
|
|
** `-DWITH_RPM=YES` to generate an rpm-package
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
To generate a binary package, run `make package`.
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
include::{uri-base}/raw/branch/master/CONTRIBUTING.adoc[]
|
2018-12-25 18:33:19 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
== Algorithms
|
2018-12-26 23:51:32 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
=== ltr_symmetric
|
2018-12-26 23:51:32 +01:00
|
|
|
|
|
|
|
* Create image with width=columns, height=rows.
|
|
|
|
* Set background color.
|
|
|
|
* Select half of the columns, or half of the columns + 1 if uneven.
|
2019-09-27 07:16:03 +02:00
|
|
|
** `columns / 2 + columns % 2`
|
2018-12-26 23:51:32 +01:00
|
|
|
* 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.
|
2019-09-27 07:16:03 +02:00
|
|
|
** You need `floor(log2(n_colors)) + 1` bits.
|
2018-12-26 23:51:32 +01:00
|
|
|
* Scale image proportionally to requested width.
|
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
----
|
2018-12-26 23:51:32 +01:00
|
|
|
0111 0011 1101 1100 […] 1111 0111 0101 0111
|
|
|
|
^ ^
|
|
|
|
+----------------------------+-------------->
|
|
|
|
| |
|
|
|
|
pixel matrix foreground color
|
2019-09-27 07:16:03 +02:00
|
|
|
----
|
2018-12-26 23:51:32 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
Implemented in
|
|
|
|
link:{uri-branch-master}/src/ltr_symmetric.cpp[ltr_symmetric.cpp].
|
2018-12-26 23:51:32 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
=== ltr_asymmetric
|
2018-12-27 05:21:40 +01:00
|
|
|
|
|
|
|
* 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.
|
2019-09-27 07:16:03 +02:00
|
|
|
** You need `floor(log2(n_colors)) + 1` bits.
|
2018-12-27 05:21:40 +01:00
|
|
|
* Scale image proportionally to requested width.
|
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
----
|
2018-12-27 05:21:40 +01:00
|
|
|
0111 0011 1101 1100 […] 1111 0111 0101 0111
|
|
|
|
^ ^
|
|
|
|
+----------------------------+-------------->
|
|
|
|
| |
|
|
|
|
pixel matrix foreground color
|
2019-09-27 07:16:03 +02:00
|
|
|
----
|
2018-12-27 05:21:40 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
Implemented in
|
|
|
|
link:{uri-branch-master}/src/ltr_asymmetric.cpp[ltr_asymmetric.cpp].
|
2018-12-27 05:21:40 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
=== sigil
|
2018-12-26 23:51:32 +01:00
|
|
|
|
|
|
|
* Create image with width=columns, height=rows.
|
|
|
|
* Set background color.
|
|
|
|
* Select half of the columns, or half of the columns + 1 if uneven.
|
2019-09-27 07:16:03 +02:00
|
|
|
** `columns / 2 + columns % 2`
|
2018-12-26 23:51:32 +01:00
|
|
|
* 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.
|
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
----
|
2018-12-26 23:51:32 +01:00
|
|
|
0111 0011 1101 1100
|
|
|
|
^ ^
|
|
|
|
+---------+--------->
|
|
|
|
| |
|
|
|
|
foreground color |
|
|
|
|
pixel matrix
|
2019-09-27 07:16:03 +02:00
|
|
|
----
|
2018-12-26 23:51:32 +01:00
|
|
|
|
2019-09-27 07:16:03 +02:00
|
|
|
Implemented in link:{uri-branch-master}/src/sigil.cpp[sigil.cpp].
|