aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-03-14 10:13:22 +0000
committerMario <mario@mariovavti.com>2024-03-14 10:13:22 +0000
commit55097c47c5534d4453f7494f8a1542f7beb4d588 (patch)
tree399f81bbd03fcb4bb713339d06512eee962ec8f6 /vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php
parent97b82fc77b424d051b2a472ab2318fd768151bdd (diff)
downloadvolse-hubzilla-55097c47c5534d4453f7494f8a1542f7beb4d588.tar.gz
volse-hubzilla-55097c47c5534d4453f7494f8a1542f7beb4d588.tar.bz2
volse-hubzilla-55097c47c5534d4453f7494f8a1542f7beb4d588.zip
Revert "composer update and use the fixed streams php-jcs library until the floats issue will be fixed upstream. see here for reference https://codeberg.org/streams/streams/issues/151"
This reverts commit 6bf61dfa6b585db01b607a79bd64ec9c583a9c10.
Diffstat (limited to 'vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php')
-rw-r--r--vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php b/vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php
new file mode 100644
index 000000000..76aa5ced7
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Class QRImageWithLogo
+ *
+ * @filesource QRImageWithLogo.php
+ * @created 18.11.2020
+ * @package chillerlan\QRCodeExamples
+ * @author smiley <smiley@chillerlan.net>
+ * @copyright 2020 smiley
+ * @license MIT
+ *
+ * @noinspection PhpComposerExtensionStubsInspection
+ */
+
+namespace chillerlan\QRCodeExamples;
+
+use chillerlan\QRCode\Output\{QRCodeOutputException, QRImage};
+
+use function imagecopyresampled, imagecreatefrompng, imagesx, imagesy, is_file, is_readable;
+
+/**
+ * @property \chillerlan\QRCodeExamples\LogoOptions $options
+ */
+class QRImageWithLogo extends QRImage{
+
+ /**
+ * @param string|null $file
+ * @param string|null $logo
+ *
+ * @return string
+ * @throws \chillerlan\QRCode\Output\QRCodeOutputException
+ */
+ public function dump(string $file = null, string $logo = null):string{
+ // set returnResource to true to skip further processing for now
+ $this->options->returnResource = true;
+
+ // of course you could accept other formats too (such as resource or Imagick)
+ // i'm not checking for the file type either for simplicity reasons (assuming PNG)
+ if(!is_file($logo) || !is_readable($logo)){
+ throw new QRCodeOutputException('invalid logo');
+ }
+
+ $this->matrix->setLogoSpace(
+ $this->options->logoSpaceWidth,
+ $this->options->logoSpaceHeight
+ // not utilizing the position here
+ );
+
+ // there's no need to save the result of dump() into $this->image here
+ parent::dump($file);
+
+ $im = imagecreatefrompng($logo);
+
+ // get logo image size
+ $w = imagesx($im);
+ $h = imagesy($im);
+
+ // set new logo size, leave a border of 1 module (no proportional resize/centering)
+ $lw = ($this->options->logoSpaceWidth - 2) * $this->options->scale;
+ $lh = ($this->options->logoSpaceHeight - 2) * $this->options->scale;
+
+ // get the qrcode size
+ $ql = $this->matrix->size() * $this->options->scale;
+
+ // scale the logo and copy it over. done!
+ imagecopyresampled($this->image, $im, ($ql - $lw) / 2, ($ql - $lh) / 2, 0, 0, $lw, $lh, $w, $h);
+
+ $imageData = $this->dumpImage();
+
+ if($file !== null){
+ $this->saveToFile($imageData, $file);
+ }
+
+ if($this->options->imageBase64){
+ $imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData);
+ }
+
+ return $imageData;
+ }
+
+}