Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | namespace RobThree\Auth\Providers\Qr; |
| 3 | |
| 4 | use Endroid\QrCode\ErrorCorrectionLevel; |
| 5 | use Endroid\QrCode\QrCode; |
| 6 | |
| 7 | class 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 | } |