Skip to content

Commit 2060811

Browse files
committed
Add logo option to Endroid's provider
closes #56
1 parent c3110d9 commit 2060811

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/Providers/Qr/EndroidQrCodeProvider.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class EndroidQrCodeProvider implements IQRCodeProvider
1010
public $color;
1111
public $margin;
1212
public $errorcorrectionlevel;
13+
protected $logoPath;
14+
protected $logoSize;
1315

1416
public function __construct($bgcolor = 'ffffff', $color = '000000', $margin = 0, $errorcorrectionlevel = 'H')
1517
{
@@ -19,6 +21,17 @@ public function __construct($bgcolor = 'ffffff', $color = '000000', $margin = 0,
1921
$this->errorcorrectionlevel = $this->handleErrorCorrectionLevel($errorcorrectionlevel);
2022
}
2123

24+
/**
25+
* Adds an image to the middle of the QR Code.
26+
* @param string $path Path to an image file
27+
* @param array|int $size Just the width, or [width, height]
28+
*/
29+
public function setLogo($path, $size = null)
30+
{
31+
$this->logoPath = $path;
32+
$this->logoSize = (array)$size;
33+
}
34+
2235
public function getMimeType()
2336
{
2437
return 'image/png';
@@ -34,6 +47,13 @@ public function getQRCodeImage($qrtext, $size)
3447
$qrCode->setBackgroundColor($this->bgcolor);
3548
$qrCode->setForegroundColor($this->color);
3649

50+
if ($this->logoPath) {
51+
$qrCode->setLogoPath($this->logoPath);
52+
if ($this->logoSize) {
53+
$qrCode->setLogoSize($this->logoSize[0], $this->logoSize[1]);
54+
}
55+
}
56+
3757
return $qrCode->writeString();
3858
}
3959

0 commit comments

Comments
 (0)