Added generate_base64()
the build was successful Details

This commit is contained in:
tastytea 2019-01-17 20:02:47 +01:00
parent d1a8dfd678
commit fb6eadd946
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 28 additions and 1 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.2) cmake_minimum_required (VERSION 3.2)
project(identiconpp project(identiconpp
VERSION 0.4.0 VERSION 0.5.0
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -41,6 +41,7 @@ The "sigil" algorithm generates the same results as
```C++ ```C++
// Compile with g++ $(Magick++-config --cppflags --ldflags) -lidenticonpp // Compile with g++ $(Magick++-config --cppflags --ldflags) -lidenticonpp
#include <iostream>
#include <identiconpp.hpp> #include <identiconpp.hpp>
#include <Magick++/Image.h> #include <Magick++/Image.h>
@ -51,6 +52,8 @@ int main()
Magick::Image img; Magick::Image img;
img = identicon.generate("55502f40dc8b7c769880b10874abc9d0", 200); img = identicon.generate("55502f40dc8b7c769880b10874abc9d0", 200);
img.write("identicon.png"); img.write("identicon.png");
std::cout << identicon.generate_base64("png", "5550", 200) << std::endl;
} }
``` ```

View File

@ -18,6 +18,7 @@
#include <stdexcept> #include <stdexcept>
#include <sstream> #include <sstream>
#include <cmath> #include <cmath>
#include <Magick++/Blob.h>
#include "identiconpp.hpp" #include "identiconpp.hpp"
#include "debug.hpp" #include "debug.hpp"
@ -95,6 +96,17 @@ Magick::Image Identiconpp::generate(const string &digest, const uint16_t width)
return img; 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) bool Identiconpp::get_bit(const uint16_t bit, const string &digest)
{ {
std::stringstream ss; std::stringstream ss;

View File

@ -90,6 +90,18 @@ public:
*/ */
Magick::Image generate(const string &digest, const uint16_t width = 100); 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: private:
const uint8_t _rows; const uint8_t _rows;
const uint8_t _columns; const uint8_t _columns;