2018-12-27 21:56:50 +01:00
|
|
|
**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
|
|
|
|
2018-12-28 01:57:08 +01:00
|
|
|
![](https://doc.schlomp.space/identiconpp/identicon1.png
|
|
|
|
"4x4 identicon, ltr_symmetric, 20px padding")
|
|
|
|
![](https://doc.schlomp.space/identiconpp/identicon2.png
|
|
|
|
"5x5 identicon, sigil")
|
|
|
|
![](https://doc.schlomp.space/identiconpp/identicon3.png
|
|
|
|
"5x5 identicon, ltr_asymmetric")
|
|
|
|
![](https://doc.schlomp.space/identiconpp/identicon4.png
|
|
|
|
"6x4 identicon, ltr_symmetric, 10px padding")
|
|
|
|
|
2018-12-25 18:33:19 +01:00
|
|
|
## Features
|
|
|
|
|
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
|
|
|
|
2018-12-25 21:46:29 +01:00
|
|
|
## 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).
|
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
|
|
|
|
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.
|
|
|
|
|
2018-12-28 01:57:08 +01:00
|
|
|
The "sigil" algorithm generates the same results as
|
|
|
|
[sigil](https://github.com/cupcake/sigil/) and
|
|
|
|
[pydenticon](https://github.com/azaghal/pydenticon/).
|
|
|
|
|
2018-12-26 06:30:05 +01:00
|
|
|
### Example
|
|
|
|
|
|
|
|
```C++
|
|
|
|
// Compile with g++ $(Magick++-config --cppflags --ldflags) -lidenticonpp
|
|
|
|
#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");
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-12-25 18:33:19 +01:00
|
|
|
## Install
|
|
|
|
|
2018-12-26 06:30:05 +01:00
|
|
|
### Gentoo
|
2018-12-25 18:33:19 +01:00
|
|
|
|
|
|
|
Gentoo ebuilds are available via my
|
2018-12-26 06:30:05 +01:00
|
|
|
[repository](https://schlomp.space/tastytea/overlay).
|
|
|
|
|
|
|
|
### Automatically generated packages
|
|
|
|
|
|
|
|
Binary packages are generated automatically for each
|
2018-12-26 18:52:27 +01:00
|
|
|
[release](https://schlomp.space/tastytea/identiconpp/releases) in the
|
2018-12-26 06:30:05 +01:00
|
|
|
formats:
|
|
|
|
|
|
|
|
* deb
|
|
|
|
* rpm
|
|
|
|
* tar.gz
|
|
|
|
|
|
|
|
They are generated on Debian Stretch 64 bit and signed with my
|
|
|
|
[automatic signing key](https://tastytea.de/tastytea_autosign.asc).
|
2018-12-25 18:33:19 +01:00
|
|
|
|
|
|
|
### From source
|
|
|
|
|
|
|
|
#### Dependencies
|
|
|
|
|
|
|
|
* C++ compiler (tested: [gcc](https://gcc.gnu.org/) 5/6/7/8,
|
|
|
|
[clang](https://llvm.org/) 5/6)
|
|
|
|
* [cmake](https://cmake.org/) (at least 3.2)
|
|
|
|
* [imagemagick](https://www.imagemagick.org/) (tested: 7.0 / 6.7)
|
2019-01-01 16:46:17 +01:00
|
|
|
* Optional:
|
2019-01-02 06:33:43 +01:00
|
|
|
* Tests: [Catch](https://github.com/catchorg/Catch2) (tested: 2.3 / 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
|
|
|
|
|
|
|
#### Compile
|
|
|
|
|
|
|
|
```SH
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ..
|
|
|
|
make
|
|
|
|
make install
|
|
|
|
```
|
|
|
|
|
|
|
|
##### cmake options
|
|
|
|
|
|
|
|
* `-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:
|
|
|
|
* `-DWITH_DEB=YES` to generate a deb-package
|
|
|
|
* `-DWITH_RPM=YES` to generate an rpm-package
|
|
|
|
|
|
|
|
To generate a binary package, execute `make package`
|
2018-12-25 18:33:19 +01:00
|
|
|
|
|
|
|
## Contributing
|
|
|
|
|
|
|
|
Contributions are always welcome. You can submit them as pull requests or via
|
|
|
|
email to `tastytea`@`tastytea.de`.
|
|
|
|
|
|
|
|
## Contact
|
|
|
|
|
|
|
|
See https://tastytea.de/
|
|
|
|
|
|
|
|
## License & Copyright
|
|
|
|
|
|
|
|
```PLAIN
|
|
|
|
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.
|
|
|
|
```
|
2018-12-26 23:51:32 +01:00
|
|
|
|
|
|
|
## 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.
|
2018-12-27 23:23:24 +01:00
|
|
|
* You need `floor(log2(n_colors)) + 1` bits.
|
2018-12-26 23:51:32 +01:00
|
|
|
* Scale image proportionally to requested width.
|
|
|
|
|
|
|
|
```PLAIN
|
|
|
|
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)
|
|
|
|
|
2018-12-27 05:21:40 +01:00
|
|
|
### 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.
|
2018-12-27 23:23:24 +01:00
|
|
|
* * You need `floor(log2(n_colors)) + 1` bits.
|
2018-12-27 05:21:40 +01:00
|
|
|
* Scale image proportionally to requested width.
|
|
|
|
|
|
|
|
```PLAIN
|
|
|
|
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)
|
|
|
|
|
2018-12-26 23:51:32 +01:00
|
|
|
### 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.
|
|
|
|
|
|
|
|
```PLAIN
|
|
|
|
0111 0011 1101 1100
|
|
|
|
^ ^
|
|
|
|
+---------+--------->
|
|
|
|
| |
|
|
|
|
foreground color |
|
|
|
|
pixel matrix
|
|
|
|
```
|
|
|
|
|
|
|
|
Implemented in [sigil.cpp]
|
|
|
|
(https://schlomp.space/tastytea/identiconpp/src/branch/master/src/sigil.cpp)
|