-
-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathGoogleChartsQrCodeProvider.php
More file actions
40 lines (33 loc) · 1.06 KB
/
GoogleChartsQrCodeProvider.php
File metadata and controls
40 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace RobThree\Auth\Providers\Qr;
// https://developers.google.com/chart/infographics/docs/qr_codes
class GoogleChartsQrCodeProvider extends BaseHTTPQRCodeProvider
{
public function __construct(
protected bool $verifyssl = false,
public string $errorcorrectionlevel = 'L',
public int $margin = 4,
public string $encoding = 'UTF-8'
) {
}
public function getMimeType(): string
{
return 'image/png';
}
public function getQRCodeImage(string $qrText, int $size): string
{
return $this->getContent($this->getUrl($qrText, $size));
}
public function getUrl(string $qrText, int $size): string
{
$queryParameters = [
'chs' => $size . 'x' . $size,
'chld' => strtoupper($this->errorcorrectionlevel) . '|' . $this->margin,
'cht' => 'qr',
'choe' => $this->encoding,
'chl' => $qrText,
];
return 'https://chart.googleapis.com/chart?' . http_build_query($queryParameters);
}
}