From fb6eadd94639eed5995386587844289afe050317 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 17 Jan 2019 20:02:47 +0100 Subject: [PATCH] Added generate_base64() --- CMakeLists.txt | 2 +- README.md | 3 +++ src/identiconpp.cpp | 12 ++++++++++++ src/identiconpp.hpp | 12 ++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ca3086..421b697 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.2) project(identiconpp - VERSION 0.4.0 + VERSION 0.5.0 LANGUAGES CXX ) diff --git a/README.md b/README.md index 7c44c91..16676af 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ The "sigil" algorithm generates the same results as ```C++ // Compile with g++ $(Magick++-config --cppflags --ldflags) -lidenticonpp +#include #include #include @@ -51,6 +52,8 @@ int main() Magick::Image img; img = identicon.generate("55502f40dc8b7c769880b10874abc9d0", 200); img.write("identicon.png"); + + std::cout << identicon.generate_base64("png", "5550", 200) << std::endl; } ``` diff --git a/src/identiconpp.cpp b/src/identiconpp.cpp index 4160e41..22c1923 100644 --- a/src/identiconpp.cpp +++ b/src/identiconpp.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "identiconpp.hpp" #include "debug.hpp" @@ -95,6 +96,17 @@ Magick::Image Identiconpp::generate(const string &digest, const uint16_t width) return img; } +const string Identiconpp::generate_base64(const string &magick, + const string &digest, + const uint16_t width) +{ + Magick::Image img = generate(digest, width); + Magick::Blob blob; + img.magick(magick); + img.write(&blob); + return blob.base64(); +} + bool Identiconpp::get_bit(const uint16_t bit, const string &digest) { std::stringstream ss; diff --git a/src/identiconpp.hpp b/src/identiconpp.hpp index f5517e7..56277a5 100644 --- a/src/identiconpp.hpp +++ b/src/identiconpp.hpp @@ -90,6 +90,18 @@ public: */ Magick::Image generate(const string &digest, const uint16_t width = 100); + /*! + * @brief Generates identicon from digest. + * + * @param magick See http://imagemagick.org/script/formats.php + * @param digest The pre-computed digest + * @param width The width of the image in pixels + * + * @return The image as base64-string + */ + const string generate_base64(const string &magick, const string &digest, + const uint16_t width = 100); + private: const uint8_t _rows; const uint8_t _columns;