Add logo option to Endroid's provider

closes #56
This commit is contained in:
Igor Santos
2021-01-23 19:10:34 -03:00
parent c3110d9760
commit 2060811d88
@@ -10,6 +10,8 @@ class EndroidQrCodeProvider implements IQRCodeProvider
public $color;
public $margin;
public $errorcorrectionlevel;
protected $logoPath;
protected $logoSize;
public function __construct($bgcolor = 'ffffff', $color = '000000', $margin = 0, $errorcorrectionlevel = 'H')
{
@@ -19,6 +21,17 @@ class EndroidQrCodeProvider implements IQRCodeProvider
$this->errorcorrectionlevel = $this->handleErrorCorrectionLevel($errorcorrectionlevel);
}
/**
* Adds an image to the middle of the QR Code.
* @param string $path Path to an image file
* @param array|int $size Just the width, or [width, height]
*/
public function setLogo($path, $size = null)
{
$this->logoPath = $path;
$this->logoSize = (array)$size;
}
public function getMimeType()
{
return 'image/png';
@@ -34,6 +47,13 @@ class EndroidQrCodeProvider implements IQRCodeProvider
$qrCode->setBackgroundColor($this->bgcolor);
$qrCode->setForegroundColor($this->color);
if ($this->logoPath) {
$qrCode->setLogoPath($this->logoPath);
if ($this->logoSize) {
$qrCode->setLogoSize($this->logoSize[0], $this->logoSize[1]);
}
}
return $qrCode->writeString();
}