diff options
author | Roland Reichwein <mail@reichwein.it> | 2022-12-03 16:12:14 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2022-12-03 16:12:14 +0100 |
commit | 70131428edce8d7c6476a902d015b30b78e5f862 (patch) | |
tree | f522c3efc0e9901d59e91da59f36a52e927e9523 /qrcode.cpp | |
parent | bdf314288794e5ca898db9d07b1553182ea4d7ea (diff) |
Version 1.1: Added QR Codev1.1
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()}; +} |