#include "qrcode.h" #include #include #include using namespace qrcodegen; using namespace Magick; void QRCode::init() { Magick::InitializeMagick(NULL); } std::string QRCode::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); 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()}; }