Skip to content

Commit d8bf297

Browse files
committed
🚿
1 parent f012a15 commit d8bf297

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

examples/QRImageWithText.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@
33
* Class QRImageWithText
44
*
55
* example for additional text
6-
* @link https://github.com/chillerlan/php-qrcode/issues/35
6+
*
7+
* @link https://github.com/chillerlan/php-qrcode/issues/35
78
*
89
* @filesource QRImageWithText.php
910
* @created 22.06.2019
1011
* @package chillerlan\QRCodeExamples
1112
* @author smiley <[email protected]>
1213
* @copyright 2019 smiley
1314
* @license MIT
15+
*
16+
* @noinspection PhpComposerExtensionStubsInspection
1417
*/
1518

1619
namespace chillerlan\QRCodeExamples;
1720

1821
use chillerlan\QRCode\Output\QRImage;
22+
use function base64_encode, imagechar, imagecolorallocate, imagecolortransparent, imagecopymerge, imagecreatetruecolor,
23+
imagedestroy, imagefilledrectangle, imagefontwidth, in_array, round, str_split, strlen;
1924

2025
class QRImageWithText extends QRImage{
2126

@@ -26,14 +31,14 @@ class QRImageWithText extends QRImage{
2631
* @return string
2732
*/
2833
public function dump(string $file = null, string $text = null):string{
29-
$this->image = \imagecreatetruecolor($this->length, $this->length);
30-
$background = \imagecolorallocate($this->image, ...$this->options->imageTransparencyBG);
34+
$this->image = imagecreatetruecolor($this->length, $this->length);
35+
$background = imagecolorallocate($this->image, ...$this->options->imageTransparencyBG);
3136

32-
if((bool)$this->options->imageTransparent && \in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){
33-
\imagecolortransparent($this->image, $background);
37+
if((bool)$this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){
38+
imagecolortransparent($this->image, $background);
3439
}
3540

36-
\imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $background);
41+
imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $background);
3742

3843
foreach($this->matrix->matrix() as $y => $row){
3944
foreach($row as $x => $M_TYPE){
@@ -49,7 +54,7 @@ public function dump(string $file = null, string $text = null):string{
4954
$imageData = $this->dumpImage($file);
5055

5156
if((bool)$this->options->imageBase64){
52-
$imageData = 'data:image/'.$this->options->outputType.';base64,'.\base64_encode($imageData);
57+
$imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData);
5358
}
5459

5560
return $imageData;
@@ -63,36 +68,36 @@ protected function addText(string $text):void{
6368
$qrcode = $this->image;
6469

6570
// options things
66-
$textSize = 3; // see imagefontheight() and imagefontwidth()
71+
$textSize = 3; // see imagefontheight() and imagefontwidth()
6772
$textBG = [200, 200, 200];
6873
$textColor = [50, 50, 50];
6974

7075
$bgWidth = $this->length;
7176
$bgHeight = $bgWidth + 20; // 20px extra space
7277

7378
// create a new image with additional space
74-
$this->image = \imagecreatetruecolor($bgWidth, $bgHeight);
75-
$background = \imagecolorallocate($this->image, ...$textBG);
79+
$this->image = imagecreatetruecolor($bgWidth, $bgHeight);
80+
$background = imagecolorallocate($this->image, ...$textBG);
7681

7782
// allow transparency
78-
if((bool)$this->options->imageTransparent && \in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){
79-
\imagecolortransparent($this->image, $background);
83+
if((bool)$this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){
84+
imagecolortransparent($this->image, $background);
8085
}
8186

8287
// fill the background
83-
\imagefilledrectangle($this->image, 0, 0, $bgWidth, $bgHeight, $background);
88+
imagefilledrectangle($this->image, 0, 0, $bgWidth, $bgHeight, $background);
8489

8590
// copy over the qrcode
86-
\imagecopymerge($this->image, $qrcode, 0, 0, 0, 0, $this->length, $this->length, 100);
87-
\imagedestroy($qrcode);
91+
imagecopymerge($this->image, $qrcode, 0, 0, 0, 0, $this->length, $this->length, 100);
92+
imagedestroy($qrcode);
8893

89-
$fontColor = \imagecolorallocate($this->image, ...$textColor);
90-
$w = \imagefontwidth($textSize);
91-
$x = \round(($bgWidth - \strlen($text) * $w) / 2);
94+
$fontColor = imagecolorallocate($this->image, ...$textColor);
95+
$w = imagefontwidth($textSize);
96+
$x = round(($bgWidth - strlen($text) * $w) / 2);
9297

9398
// loop through the string and draw the letters
94-
foreach(\str_split($text) as $i => $chr){
95-
\imagechar($this->image, $textSize, $i * $w + $x, $this->length, $chr, $fontColor);
99+
foreach(str_split($text) as $i => $chr){
100+
imagechar($this->image, $textSize, $i * $w + $x, $this->length, $chr, $fontColor);
96101
}
97102
}
98103

examples/imageWithLogo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* @noinspection PhpIllegalPsrClassPathInspection
2323
*/
2424
class LogoOptions extends QROptions{
25-
protected int $logoWidth;
26-
protected int $logoHeight;
25+
protected $logoWidth;
26+
protected $logoHeight;
2727
}
2828

2929
$options = new LogoOptions;

0 commit comments

Comments
 (0)