From 70131428edce8d7c6476a902d015b30b78e5f862 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 3 Dec 2022 16:12:14 +0100 Subject: Version 1.1: Added QR Code --- qrcode.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 qrcode.cpp (limited to 'qrcode.cpp') 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 + +#include +#include + +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()}; +} -- cgit v1.2.3