From 3fd785654372d493c031d9b541ab33a881023a32 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 26 Feb 2021 19:16:17 +0300 Subject: * switch to composer for qrcode and otp dependencies * move most OTP-related stuff into userhelper * remove old phpqrcode and otphp libraries --- .../php-qrcode/examples/MyCustomOutput.php | 36 +++++++ .../php-qrcode/examples/QRImageWithLogo.php | 81 ++++++++++++++++ .../php-qrcode/examples/QRImageWithText.php | 104 +++++++++++++++++++++ .../php-qrcode/examples/custom_output.php | 38 ++++++++ .../php-qrcode/examples/example_image.png | Bin 0 -> 2279 bytes .../chillerlan/php-qrcode/examples/example_svg.png | Bin 0 -> 15925 bytes vendor/chillerlan/php-qrcode/examples/fpdf.php | 47 ++++++++++ vendor/chillerlan/php-qrcode/examples/html.php | 102 ++++++++++++++++++++ vendor/chillerlan/php-qrcode/examples/image.php | 60 ++++++++++++ .../php-qrcode/examples/imageWithLogo.php | 44 +++++++++ .../php-qrcode/examples/imageWithText.php | 33 +++++++ vendor/chillerlan/php-qrcode/examples/imagick.php | 59 ++++++++++++ vendor/chillerlan/php-qrcode/examples/octocat.png | Bin 0 -> 2468 bytes vendor/chillerlan/php-qrcode/examples/svg.php | 77 +++++++++++++++ vendor/chillerlan/php-qrcode/examples/text.php | 68 ++++++++++++++ 15 files changed, 749 insertions(+) create mode 100644 vendor/chillerlan/php-qrcode/examples/MyCustomOutput.php create mode 100644 vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php create mode 100644 vendor/chillerlan/php-qrcode/examples/QRImageWithText.php create mode 100644 vendor/chillerlan/php-qrcode/examples/custom_output.php create mode 100644 vendor/chillerlan/php-qrcode/examples/example_image.png create mode 100644 vendor/chillerlan/php-qrcode/examples/example_svg.png create mode 100644 vendor/chillerlan/php-qrcode/examples/fpdf.php create mode 100644 vendor/chillerlan/php-qrcode/examples/html.php create mode 100644 vendor/chillerlan/php-qrcode/examples/image.php create mode 100644 vendor/chillerlan/php-qrcode/examples/imageWithLogo.php create mode 100644 vendor/chillerlan/php-qrcode/examples/imageWithText.php create mode 100644 vendor/chillerlan/php-qrcode/examples/imagick.php create mode 100644 vendor/chillerlan/php-qrcode/examples/octocat.png create mode 100644 vendor/chillerlan/php-qrcode/examples/svg.php create mode 100644 vendor/chillerlan/php-qrcode/examples/text.php (limited to 'vendor/chillerlan/php-qrcode/examples') diff --git a/vendor/chillerlan/php-qrcode/examples/MyCustomOutput.php b/vendor/chillerlan/php-qrcode/examples/MyCustomOutput.php new file mode 100644 index 000000000..3c01f8646 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/MyCustomOutput.php @@ -0,0 +1,36 @@ + + * @copyright 2017 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\Output\QROutputAbstract; + +class MyCustomOutput extends QROutputAbstract{ + + protected function setModuleValues():void{ + // TODO: Implement setModuleValues() method. + } + + public function dump(string $file = null){ + + $output = ''; + + for($row = 0; $row < $this->moduleCount; $row++){ + for($col = 0; $col < $this->moduleCount; $col++){ + $output .= (int)$this->matrix->check($col, $row); + } + } + + return $output; + } + +} diff --git a/vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php b/vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php new file mode 100644 index 000000000..f9d94ae34 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/QRImageWithLogo.php @@ -0,0 +1,81 @@ + + * @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->logoWidth, + $this->options->logoHeight + // 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 + $lw = ($this->options->logoWidth - 2) * $this->options->scale; + $lh = ($this->options->logoHeight - 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; + } + +} diff --git a/vendor/chillerlan/php-qrcode/examples/QRImageWithText.php b/vendor/chillerlan/php-qrcode/examples/QRImageWithText.php new file mode 100644 index 000000000..5ca572f30 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/QRImageWithText.php @@ -0,0 +1,104 @@ + + * @copyright 2019 smiley + * @license MIT + * + * @noinspection PhpComposerExtensionStubsInspection + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\Output\QRImage; +use function base64_encode, imagechar, imagecolorallocate, imagecolortransparent, imagecopymerge, imagecreatetruecolor, + imagedestroy, imagefilledrectangle, imagefontwidth, in_array, round, str_split, strlen; + +class QRImageWithText extends QRImage{ + + /** + * @param string|null $file + * @param string|null $text + * + * @return string + */ + public function dump(string $file = null, string $text = null):string{ + $this->image = imagecreatetruecolor($this->length, $this->length); + $background = imagecolorallocate($this->image, ...$this->options->imageTransparencyBG); + + if((bool)$this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){ + imagecolortransparent($this->image, $background); + } + + imagefilledrectangle($this->image, 0, 0, $this->length, $this->length, $background); + + foreach($this->matrix->matrix() as $y => $row){ + foreach($row as $x => $M_TYPE){ + $this->setPixel($x, $y, $this->moduleValues[$M_TYPE]); + } + } + + // render text output if a string is given + if($text !== null){ + $this->addText($text); + } + + $imageData = $this->dumpImage($file); + + if((bool)$this->options->imageBase64){ + $imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData); + } + + return $imageData; + } + + /** + * @param string $text + */ + protected function addText(string $text):void{ + // save the qrcode image + $qrcode = $this->image; + + // options things + $textSize = 3; // see imagefontheight() and imagefontwidth() + $textBG = [200, 200, 200]; + $textColor = [50, 50, 50]; + + $bgWidth = $this->length; + $bgHeight = $bgWidth + 20; // 20px extra space + + // create a new image with additional space + $this->image = imagecreatetruecolor($bgWidth, $bgHeight); + $background = imagecolorallocate($this->image, ...$textBG); + + // allow transparency + if((bool)$this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){ + imagecolortransparent($this->image, $background); + } + + // fill the background + imagefilledrectangle($this->image, 0, 0, $bgWidth, $bgHeight, $background); + + // copy over the qrcode + imagecopymerge($this->image, $qrcode, 0, 0, 0, 0, $this->length, $this->length, 100); + imagedestroy($qrcode); + + $fontColor = imagecolorallocate($this->image, ...$textColor); + $w = imagefontwidth($textSize); + $x = round(($bgWidth - strlen($text) * $w) / 2); + + // loop through the string and draw the letters + foreach(str_split($text) as $i => $chr){ + imagechar($this->image, $textSize, $i * $w + $x, $this->length, $chr, $fontColor); + } + } + +} diff --git a/vendor/chillerlan/php-qrcode/examples/custom_output.php b/vendor/chillerlan/php-qrcode/examples/custom_output.php new file mode 100644 index 000000000..71ea62682 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/custom_output.php @@ -0,0 +1,38 @@ + + * @copyright 2017 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\{QRCode, QROptions}; + +require_once __DIR__.'/../vendor/autoload.php'; + +$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; + +// invoke the QROutputInterface manually +$options = new QROptions([ + 'version' => 5, + 'eccLevel' => QRCode::ECC_L, +]); + +$qrOutputInterface = new MyCustomOutput($options, (new QRCode($options))->getMatrix($data)); + +var_dump($qrOutputInterface->dump()); + + +// or just +$options = new QROptions([ + 'version' => 5, + 'eccLevel' => QRCode::ECC_L, + 'outputType' => QRCode::OUTPUT_CUSTOM, + 'outputInterface' => MyCustomOutput::class, +]); + +var_dump((new QRCode($options))->render($data)); diff --git a/vendor/chillerlan/php-qrcode/examples/example_image.png b/vendor/chillerlan/php-qrcode/examples/example_image.png new file mode 100644 index 000000000..b4a80f2ab Binary files /dev/null and b/vendor/chillerlan/php-qrcode/examples/example_image.png differ diff --git a/vendor/chillerlan/php-qrcode/examples/example_svg.png b/vendor/chillerlan/php-qrcode/examples/example_svg.png new file mode 100644 index 000000000..f1e7b32f7 Binary files /dev/null and b/vendor/chillerlan/php-qrcode/examples/example_svg.png differ diff --git a/vendor/chillerlan/php-qrcode/examples/fpdf.php b/vendor/chillerlan/php-qrcode/examples/fpdf.php new file mode 100644 index 000000000..9c690a7f7 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/fpdf.php @@ -0,0 +1,47 @@ + 7, + 'outputType' => QRCode::OUTPUT_FPDF, + 'eccLevel' => QRCode::ECC_L, + 'scale' => 5, + 'imageBase64' => false, + 'moduleValues' => [ + // finder + 1536 => [0, 63, 255], // dark (true) + 6 => [255, 255, 255], // light (false), white is the transparency color and is enabled by default + // alignment + 2560 => [255, 0, 255], + 10 => [255, 255, 255], + // timing + 3072 => [255, 0, 0], + 12 => [255, 255, 255], + // format + 3584 => [67, 191, 84], + 14 => [255, 255, 255], + // version + 4096 => [62, 174, 190], + 16 => [255, 255, 255], + // data + 1024 => [0, 0, 0], + 4 => [255, 255, 255], + // darkmodule + 512 => [0, 0, 0], + // separator + 8 => [255, 255, 255], + // quietzone + 18 => [255, 255, 255], + ], +]); + +\header('Content-type: application/pdf'); + +echo (new QRCode($options))->render($data); diff --git a/vendor/chillerlan/php-qrcode/examples/html.php b/vendor/chillerlan/php-qrcode/examples/html.php new file mode 100644 index 000000000..aa5305d24 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/html.php @@ -0,0 +1,102 @@ + + * @copyright 2017 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\{QRCode, QROptions}; + +require_once '../vendor/autoload.php'; + +header('Content-Type: text/html; charset=utf-8'); + +?> + + + + + + QRCode test + + + +
+ 5, + 'outputType' => QRCode::OUTPUT_MARKUP_HTML, + 'eccLevel' => QRCode::ECC_L, + 'moduleValues' => [ + // finder + 1536 => '#A71111', // dark (true) + 6 => '#FFBFBF', // light (false) + // alignment + 2560 => '#A70364', + 10 => '#FFC9C9', + // timing + 3072 => '#98005D', + 12 => '#FFB8E9', + // format + 3584 => '#003804', + 14 => '#00FB12', + // version + 4096 => '#650098', + 16 => '#E0B8FF', + // data + 1024 => '#4A6000', + 4 => '#ECF9BE', + // darkmodule + 512 => '#080063', + // separator + 8 => '#AFBFBF', + // quietzone + 18 => '#FFFFFF', + ], + ]); + + echo (new QRCode($options))->render($data); + +?> +
+ + + + + diff --git a/vendor/chillerlan/php-qrcode/examples/image.php b/vendor/chillerlan/php-qrcode/examples/image.php new file mode 100644 index 000000000..89ba2a9a8 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/image.php @@ -0,0 +1,60 @@ + + * @copyright 2017 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\{QRCode, QROptions}; + +require_once __DIR__.'/../vendor/autoload.php'; + +$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; + +$options = new QROptions([ + 'version' => 7, + 'outputType' => QRCode::OUTPUT_IMAGE_PNG, + 'eccLevel' => QRCode::ECC_L, + 'scale' => 5, + 'imageBase64' => false, + 'moduleValues' => [ + // finder + 1536 => [0, 63, 255], // dark (true) + 6 => [255, 255, 255], // light (false), white is the transparency color and is enabled by default + // alignment + 2560 => [255, 0, 255], + 10 => [255, 255, 255], + // timing + 3072 => [255, 0, 0], + 12 => [255, 255, 255], + // format + 3584 => [67, 191, 84], + 14 => [255, 255, 255], + // version + 4096 => [62, 174, 190], + 16 => [255, 255, 255], + // data + 1024 => [0, 0, 0], + 4 => [255, 255, 255], + // darkmodule + 512 => [0, 0, 0], + // separator + 8 => [255, 255, 255], + // quietzone + 18 => [255, 255, 255], + ], +]); + +header('Content-type: image/png'); + +echo (new QRCode($options))->render($data); + + + + + diff --git a/vendor/chillerlan/php-qrcode/examples/imageWithLogo.php b/vendor/chillerlan/php-qrcode/examples/imageWithLogo.php new file mode 100644 index 000000000..987e10c11 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/imageWithLogo.php @@ -0,0 +1,44 @@ + + * @copyright 2020 smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\{QRCode, QROptions}; + +require_once __DIR__.'/../vendor/autoload.php'; + +$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; +/** + * @property int $logoWidth + * @property int $logoHeight + * + * @noinspection PhpIllegalPsrClassPathInspection + */ +class LogoOptions extends QROptions{ + protected $logoWidth; + protected $logoHeight; +} + +$options = new LogoOptions; + +$options->version = 7; +$options->eccLevel = QRCode::ECC_H; +$options->imageBase64 = false; +$options->logoWidth = 13; +$options->logoHeight = 13; +$options->scale = 5; +$options->imageTransparent = false; + +header('Content-type: image/png'); + +$qrOutputInterface = new QRImageWithLogo($options, (new QRCode($options))->getMatrix($data)); + +// dump the output, with an additional logo +echo $qrOutputInterface->dump(null, __DIR__.'/octocat.png'); diff --git a/vendor/chillerlan/php-qrcode/examples/imageWithText.php b/vendor/chillerlan/php-qrcode/examples/imageWithText.php new file mode 100644 index 000000000..050781cba --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/imageWithText.php @@ -0,0 +1,33 @@ + + * @copyright 2019 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\{QRCode, QROptions}; + +require_once __DIR__.'/../vendor/autoload.php'; + +$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; + +$options = new QROptions([ + 'version' => 7, + 'outputType' => QRCode::OUTPUT_IMAGE_PNG, + 'scale' => 3, + 'imageBase64' => false, +]); + +header('Content-type: image/png'); + +$qrOutputInterface = new QRImageWithText($options, (new QRCode($options))->getMatrix($data)); + +// dump the output, with additional text +echo $qrOutputInterface->dump(null, 'example text'); diff --git a/vendor/chillerlan/php-qrcode/examples/imagick.php b/vendor/chillerlan/php-qrcode/examples/imagick.php new file mode 100644 index 000000000..6bec4d02e --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/imagick.php @@ -0,0 +1,59 @@ + + * @copyright 2017 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\{QRCode, QROptions}; + +require_once __DIR__.'/../vendor/autoload.php'; + +$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; + +$options = new QROptions([ + 'version' => 7, + 'outputType' => QRCode::OUTPUT_IMAGICK, + 'eccLevel' => QRCode::ECC_L, + 'scale' => 5, + 'moduleValues' => [ + // finder + 1536 => '#A71111', // dark (true) + 6 => '#FFBFBF', // light (false) + // alignment + 2560 => '#A70364', + 10 => '#FFC9C9', + // timing + 3072 => '#98005D', + 12 => '#FFB8E9', + // format + 3584 => '#003804', + 14 => '#00FB12', + // version + 4096 => '#650098', + 16 => '#E0B8FF', + // data + 1024 => '#4A6000', + 4 => '#ECF9BE', + // darkmodule + 512 => '#080063', + // separator + 8 => '#DDDDDD', + // quietzone + 18 => '#DDDDDD', + ], +]); + +header('Content-type: image/png'); + +echo (new QRCode($options))->render($data); + + + + + diff --git a/vendor/chillerlan/php-qrcode/examples/octocat.png b/vendor/chillerlan/php-qrcode/examples/octocat.png new file mode 100644 index 000000000..f9050b935 Binary files /dev/null and b/vendor/chillerlan/php-qrcode/examples/octocat.png differ diff --git a/vendor/chillerlan/php-qrcode/examples/svg.php b/vendor/chillerlan/php-qrcode/examples/svg.php new file mode 100644 index 000000000..a7a159d70 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/svg.php @@ -0,0 +1,77 @@ + + * @copyright 2017 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\{QRCode, QROptions}; + +require_once __DIR__.'/../vendor/autoload.php'; + +$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; +$gzip = true; + +$options = new QROptions([ + 'version' => 7, + 'outputType' => QRCode::OUTPUT_MARKUP_SVG, + 'eccLevel' => QRCode::ECC_L, + 'svgViewBoxSize' => 530, + 'addQuietzone' => true, + 'cssClass' => 'my-css-class', + 'svgOpacity' => 1.0, + 'svgDefs' => ' + + + + + + + + + ', + 'moduleValues' => [ + // finder + 1536 => 'url(#g1)', // dark (true) + 6 => '#fff', // light (false) + // alignment + 2560 => 'url(#g1)', + 10 => '#fff', + // timing + 3072 => 'url(#g1)', + 12 => '#fff', + // format + 3584 => 'url(#g1)', + 14 => '#fff', + // version + 4096 => 'url(#g1)', + 16 => '#fff', + // data + 1024 => 'url(#g2)', + 4 => '#fff', + // darkmodule + 512 => 'url(#g1)', + // separator + 8 => '#fff', + // quietzone + 18 => '#fff', + ], +]); + +$qrcode = (new QRCode($options))->render($data); + +header('Content-type: image/svg+xml'); + +if($gzip === true){ + header('Vary: Accept-Encoding'); + header('Content-Encoding: gzip'); + $qrcode = gzencode($qrcode ,9); +} +echo $qrcode; + + diff --git a/vendor/chillerlan/php-qrcode/examples/text.php b/vendor/chillerlan/php-qrcode/examples/text.php new file mode 100644 index 000000000..9bdf154f0 --- /dev/null +++ b/vendor/chillerlan/php-qrcode/examples/text.php @@ -0,0 +1,68 @@ + + * @copyright 2017 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\{QRCode, QROptions}; + +require_once __DIR__.'/../vendor/autoload.php'; + +$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; + +$options = new QROptions([ + 'version' => 5, + 'outputType' => QRCode::OUTPUT_STRING_TEXT, + 'eccLevel' => QRCode::ECC_L, +]); + +//
 to view it in a browser
+echo '
'.(new QRCode($options))->render($data).'
'; + + +// custom values +$options = new QROptions([ + 'version' => 5, + 'outputType' => QRCode::OUTPUT_STRING_TEXT, + 'eccLevel' => QRCode::ECC_L, + 'moduleValues' => [ + // finder + 1536 => 'A', // dark (true) + 6 => 'a', // light (false) + // alignment + 2560 => 'B', + 10 => 'b', + // timing + 3072 => 'C', + 12 => 'c', + // format + 3584 => 'D', + 14 => 'd', + // version + 4096 => 'E', + 16 => 'e', + // data + 1024 => 'F', + 4 => 'f', + // darkmodule + 512 => 'G', + // separator + 8 => 'h', + // quietzone + 18 => 'i', + ], +]); + +//
 to view it in a browser
+echo '
'.(new QRCode($options))->render($data).'
'; + + + + + -- cgit v1.2.3