From 957128bcfedf8e26be61d9ebe1052e162858bcbf Mon Sep 17 00:00:00 2001 From: SavageCore Date: Wed, 20 Nov 2019 17:36:27 +0000 Subject: [PATCH] Implement `endroid/qr-code` support --- lib/Providers/Qr/EndroidQrCodeProvider.php | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 lib/Providers/Qr/EndroidQrCodeProvider.php diff --git a/lib/Providers/Qr/EndroidQrCodeProvider.php b/lib/Providers/Qr/EndroidQrCodeProvider.php new file mode 100755 index 0000000..735f8a0 --- /dev/null +++ b/lib/Providers/Qr/EndroidQrCodeProvider.php @@ -0,0 +1,65 @@ +bgcolor = $this->handleColor($bgcolor); + $this->color = $this->handleColor($color); + $this->margin = $margin; + $this->errorcorrectionlevel = $this->handleErrorCorrectionLevel($errorcorrectionlevel); + } + + public function getMimeType() + { + return 'image/png'; + } + + public function getQRCodeImage($qrtext, $size) + { + $qrCode = new QrCode($qrtext); + $qrCode->setSize($size); + + $qrCode->setErrorCorrectionLevel($this->errorcorrectionlevel); + $qrCode->setMargin($this->margin); + $qrCode->setBackgroundColor($this->bgcolor); + $qrCode->setForegroundColor($this->color); + + return $qrCode->writeString(); + } + + private function handleColor($color) + { + $split = str_split($color, 2); + $r = hexdec($split[0]); + $g = hexdec($split[1]); + $b = hexdec($split[2]); + + return ['r' => $r, 'g' => $g, 'b' => $b, 'a' => 0]; + } + + private function handleErrorCorrectionLevel($level) + { + switch ($level) { + case 'L': + return ErrorCorrectionLevel::LOW(); + case 'M': + return ErrorCorrectionLevel::MEDIUM(); + case 'Q': + return ErrorCorrectionLevel::QUARTILE(); + case 'H': + return ErrorCorrectionLevel::HIGH(); + default: + return ErrorCorrectionLevel::HIGH(); + } + } +}