EndroidQrCodeWithLogoProvider.php 916 B

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