identiconpp is a library to generate identicons for C++ and C.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

example.cpp 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* This file is part of identiconpp.
  2. * Public Domain / CC-0
  3. *
  4. * Compile with g++ $(pkg-config --libs --cflags identiconpp)
  5. */
  6. #include <string>
  7. #include <vector>
  8. #include "identiconpp.hpp"
  9. #include <Magick++/Image.h>
  10. int main(int argc, char *argv[])
  11. {
  12. // sha256(test@example.com)
  13. std::string digest = "973dfe463ec85785f5f95af5ba3906ee"
  14. "db2d931c24e69824a89ea65dba4e813b";
  15. const std::vector<std::string> colors =
  16. {
  17. "800000ff",
  18. "008000ff",
  19. "000080ff",
  20. "808000ff",
  21. "008080ff",
  22. "800080ff"
  23. };
  24. Magick::Image img;
  25. if (argc > 1)
  26. {
  27. digest = argv[1];
  28. }
  29. {
  30. Identiconpp identicon(4, 4, Identiconpp::algorithm::ltr_symmetric,
  31. "ffffffff", colors, { 20, 20 });
  32. img = identicon.generate(digest , 200);
  33. img.write("identicon1.png");
  34. }
  35. {
  36. Identiconpp identicon(5, 5, Identiconpp::algorithm::sigil,
  37. "00000080", colors);
  38. img = identicon.generate(digest , 200);
  39. img.write("identicon2.png");
  40. }
  41. {
  42. Identiconpp identicon(5, 5, Identiconpp::algorithm::ltr_asymmetric,
  43. "000000ff", colors);
  44. img = identicon.generate(digest , 200);
  45. img.write("identicon3.png");
  46. }
  47. {
  48. Identiconpp identicon(6, 4, Identiconpp::algorithm::ltr_symmetric,
  49. "000000c0", colors, { 10, 10 });
  50. img = identicon.generate(digest , 200);
  51. img.write("identicon4.png");
  52. }
  53. return 0;
  54. }