From 08846488cc78d5a416b15cf5cfd505a1b5b901de Mon Sep 17 00:00:00 2001 From: Milan Date: Sun, 3 Oct 2021 19:14:10 +0300 Subject: [PATCH] Implemented new ChartGoogleQrCodeProvider --- .../Qr/ChartGoogleQrCodeProvider.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lib/Providers/Qr/ChartGoogleQrCodeProvider.php diff --git a/lib/Providers/Qr/ChartGoogleQrCodeProvider.php b/lib/Providers/Qr/ChartGoogleQrCodeProvider.php new file mode 100644 index 0000000..b682bff --- /dev/null +++ b/lib/Providers/Qr/ChartGoogleQrCodeProvider.php @@ -0,0 +1,61 @@ +verifyssl = false; + + $this->errorcorrectionlevel = $errorcorrectionlevel; + $this->margin = $margin; + $this->encoding = $encoding; + } + + /** + * {@inheritdoc} + */ + public function getMimeType() + { + return 'image/png'; + } + + /** + * {@inheritdoc} + */ + public function getQRCodeImage($qrtext, $size) + { + return $this->getContent($this->getUrl($qrtext, $size)); + } + + /** + * @param string $qrtext the value to encode in the QR code + * @param int|string $size the desired size of the QR code + * + * @return string file contents of the QR code + */ + public function getUrl($qrtext, $size) + { + return 'https://chart.googleapis.com/chart' + . '?chs=' . $size . 'x' . $size + . '&chld=' . urlencode(strtoupper($this->errorcorrectionlevel) . '|' . $this->margin) + . '&cht=' . 'qr' + . '&chl=' . rawurlencode($qrtext); + } +}