blob: ed8cc98c062fb79715f62755c77357036006a7e3 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2namespace RobThree\Auth\Providers\Qr;
3
4use Endroid\QrCode\ErrorCorrectionLevel;
5use Endroid\QrCode\QrCode;
6
7class EndroidQrCodeWithLogoProvider extends EndroidQrCodeProvider
8{
9 protected $logoPath;
10 protected $logoSize;
11
12 /**
13 * Adds an image to the middle of the QR Code.
14 * @param string $path Path to an image file
15 * @param array|int $size Just the width, or [width, height]
16 */
17 public function setLogo($path, $size = null)
18 {
19 $this->logoPath = $path;
20 $this->logoSize = (array)$size;
21 }
22
23 protected function qrCodeInstance($qrtext, $size) {
24 $qrCode = parent::qrCodeInstance($qrtext, $size);
25
26 if ($this->logoPath) {
27 $qrCode->setLogoPath($this->logoPath);
28 if ($this->logoSize) {
29 $qrCode->setLogoSize($this->logoSize[0], $this->logoSize[1]);
30 }
31 }
32
33 return $qrCode;
34 }
35}