diff options
Diffstat (limited to 'qrcode.cpp')
-rw-r--r-- | qrcode.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/qrcode.cpp b/qrcode.cpp new file mode 100644 index 0000000..cd5fab8 --- /dev/null +++ b/qrcode.cpp @@ -0,0 +1,32 @@ +#include "qrcode.h" + +#include <fmt/format.h> + +#include <qrcodegen/qrcodegen.hpp> +#include <ImageMagick-6/Magick++.h> + +using namespace qrcodegen; +using namespace Magick; + +std::string getQRCode(const std::string& data) +{ + QrCode qrc {QrCode::encodeText(data.c_str(), QrCode::Ecc::MEDIUM)}; + + int size {qrc.getSize()}; + + Image image(fmt::format("{0}x{0}", size).c_str(), "white"); + image.type(GrayscaleType); + //image.size(fmt::format("{0}x{0}", size)); + + for (int x = 0; x < size; x++) { + for (int y = 0; y < size; y++) { + image.pixelColor(x, y, qrc.getModule(x, y) ? "black" : "white"); + } + } + + image.magick("PNG"); + + Blob blob; + image.write(&blob); + return std::string{(char*)blob.data(), blob.length()}; +} |