blob: cc094c31908f43034033805c172feea6e3ee5dc7 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001<?php
2
3namespace RobThree\Auth\Providers\Qr;
4
5// https://image-charts.com
6class ImageChartsQRCodeProvider extends BaseHTTPQRCodeProvider
7{
8 public $errorcorrectionlevel;
9 public $margin;
10
11 function __construct($verifyssl = false, $errorcorrectionlevel = 'L', $margin = 1)
12 {
13 if (!is_bool($verifyssl))
14 throw new \QRException('VerifySSL must be bool');
15
16 $this->verifyssl = $verifyssl;
17
18 $this->errorcorrectionlevel = $errorcorrectionlevel;
19 $this->margin = $margin;
20 }
21
22 public function getMimeType()
23 {
24 return 'image/png';
25 }
26
27 public function getQRCodeImage($qrtext, $size)
28 {
29 return $this->getContent($this->getUrl($qrtext, $size));
30 }
31
32 public function getUrl($qrtext, $size)
33 {
34 return 'https://image-charts.com/chart?cht=qr'
35 . '&chs=' . ceil($size/2) . 'x' . ceil($size/2)
36 . '&chld=' . $this->errorcorrectionlevel . '|' . $this->margin
37 . '&chl=' . rawurlencode($qrtext);
38 }
39}