From 6b92bb4c6fd9559ef3f6f295ba1fb2aa33f20990 Mon Sep 17 00:00:00 2001 From: smiley Date: Sun, 12 Mar 2023 02:16:38 +0100 Subject: [PATCH] :shower: examples cleanup --- examples/MyCustomOutput.php | 36 ------------ examples/QRImageWithLogo.php | 76 ------------------------- examples/QRImageWithText.php | 98 --------------------------------- examples/custom_output.php | 31 +++++++++-- examples/fpdf.php | 76 +++++++++++++------------ examples/html.php | 81 +++++++++++++-------------- examples/image.php | 47 +++++++--------- examples/imageWithLogo.php | 69 +++++++++++++++++++++-- examples/imageWithText.php | 84 +++++++++++++++++++++++++++- examples/imagick.php | 44 +++++++-------- examples/qrcode-interactive.php | 36 ++++++------ examples/svg.php | 46 ++++++++-------- examples/text.php | 54 +++++++----------- tests/Output/QRStringTest.php | 16 ------ 14 files changed, 351 insertions(+), 443 deletions(-) delete mode 100644 examples/MyCustomOutput.php delete mode 100644 examples/QRImageWithLogo.php delete mode 100644 examples/QRImageWithText.php diff --git a/examples/MyCustomOutput.php b/examples/MyCustomOutput.php deleted file mode 100644 index 75835b0e9..000000000 --- a/examples/MyCustomOutput.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @copyright 2017 Smiley - * @license MIT - */ - -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); - } - - $output .= \PHP_EOL; - } - - return $output; - } - -} diff --git a/examples/QRImageWithLogo.php b/examples/QRImageWithLogo.php deleted file mode 100644 index fd84800ac..000000000 --- a/examples/QRImageWithLogo.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @copyright 2020 smiley - * @license MIT - * - * @noinspection PhpComposerExtensionStubsInspection - */ - -use chillerlan\QRCode\Output\{QRCodeOutputException, QRImage}; - -use function imagecopyresampled, imagecreatefrompng, imagesx, imagesy, is_file, is_readable; - -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; - } - -} diff --git a/examples/QRImageWithText.php b/examples/QRImageWithText.php deleted file mode 100644 index 120fbf01a..000000000 --- a/examples/QRImageWithText.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @copyright 2019 smiley - * @license MIT - * - * @noinspection PhpComposerExtensionStubsInspection - */ - -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{ - // set returnResource to true to skip further processing for now - $this->options->returnResource = true; - - // there's no need to save the result of dump() into $this->image here - parent::dump($file); - - // render text output if a string is given - if($text !== null){ - $this->addText($text); - } - - $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; - } - - /** - * @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($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, (int)($i * $w + $x), $this->length, $chr, $fontColor); - } - } - -} diff --git a/examples/custom_output.php b/examples/custom_output.php index 86f45c99b..e00f2146c 100644 --- a/examples/custom_output.php +++ b/examples/custom_output.php @@ -9,10 +9,33 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Output\QROutputAbstract; require_once __DIR__.'/../vendor/autoload.php'; -$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; +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); + } + + $output .= PHP_EOL; + } + + return $output; + } + +} + // invoke the QROutputInterface manually $options = new QROptions([ @@ -20,9 +43,9 @@ $options = new QROptions([ 'eccLevel' => QRCode::ECC_L, ]); -$qrOutputInterface = new MyCustomOutput($options, (new QRCode($options))->getMatrix($data)); +$qrOutputInterface = new MyCustomOutput($options, (new QRCode($options))->getMatrix('https://www.youtube.com/watch?v=dQw4w9WgXcQ')); -var_dump($qrOutputInterface->dump()); +echo '
'.$qrOutputInterface->dump().'
'; // or just @@ -33,4 +56,4 @@ $options = new QROptions([ 'outputInterface' => MyCustomOutput::class, ]); -var_dump((new QRCode($options))->render($data)); +echo '
'.(new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ').'
'; diff --git a/examples/fpdf.php b/examples/fpdf.php index 0b42c3e6c..aab286e2d 100644 --- a/examples/fpdf.php +++ b/examples/fpdf.php @@ -1,45 +1,51 @@ 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], - ], + 'version' => 7, + 'outputType' => QRCode::OUTPUT_FPDF, + 'eccLevel' => QRCode::ECC_L, + 'scale' => 5, + 'imageBase64' => false, + 'moduleValues' => [ + // finder + (QRMatrix::M_FINDER << 8) => [0, 63, 255], // dark (true) + (QRMatrix::M_FINDER_DOT << 8) => [0, 63, 255], + QRMatrix::M_FINDER => [255, 255, 255], // light (false), white is the transparency color and is enabled by default + // alignment + (QRMatrix::M_ALIGNMENT << 8) => [255, 0, 255], + QRMatrix::M_ALIGNMENT => [255, 255, 255], + // timing + (QRMatrix::M_TIMING << 8) => [255, 0, 0], + QRMatrix::M_TIMING => [255, 255, 255], + // format + (QRMatrix::M_FORMAT << 8) => [67, 191, 84], + QRMatrix::M_FORMAT => [255, 255, 255], + // version + (QRMatrix::M_VERSION << 8) => [62, 174, 190], + QRMatrix::M_VERSION => [255, 255, 255], + // data + (QRMatrix::M_DATA << 8) => [0, 0, 0], + QRMatrix::M_DATA => [255, 255, 255], + // darkmodule + (QRMatrix::M_DARKMODULE << 8) => [0, 0, 0], + // separator + QRMatrix::M_SEPARATOR => [255, 255, 255], + // quietzone + QRMatrix::M_QUIETZONE => [255, 255, 255], + ], ]); -\header('Content-type: application/pdf'); -echo (new QRCode($options))->render($data); +header('Content-type: application/pdf'); + +echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); diff --git a/examples/html.php b/examples/html.php index 16258552b..935210efa 100644 --- a/examples/html.php +++ b/examples/html.php @@ -1,7 +1,5 @@ * @copyright 2017 Smiley @@ -9,9 +7,45 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Data\QRMatrix; require_once '../vendor/autoload.php'; +$options = new QROptions([ + 'version' => 5, + 'outputType' => QRCode::OUTPUT_MARKUP_HTML, + 'cssClass' => 'qrcode', + 'eccLevel' => QRCode::ECC_L, + 'moduleValues' => [ + // finder + (QRMatrix::M_FINDER << 8) => '#A71111', // dark (true) + (QRMatrix::M_FINDER_DOT << 8) => '#A71111', + QRMatrix::M_FINDER => '#FFBFBF', // light (false) + // alignment + (QRMatrix::M_ALIGNMENT << 8) => '#A70364', + QRMatrix::M_ALIGNMENT => '#FFC9C9', + // timing + (QRMatrix::M_TIMING << 8) => '#98005D', + QRMatrix::M_TIMING => '#FFB8E9', + // format + (QRMatrix::M_FORMAT << 8) => '#003804', + QRMatrix::M_FORMAT => '#00FB12', + // version + (QRMatrix::M_VERSION << 8) => '#650098', + QRMatrix::M_VERSION => '#E0B8FF', + // data + (QRMatrix::M_DATA << 8) => '#4A6000', + QRMatrix::M_DATA => '#ECF9BE', + // darkmodule + (QRMatrix::M_DARKMODULE << 8) => '#080063', + // separator + QRMatrix::M_SEPARATOR => '#AFBFBF', + // quietzone + QRMatrix::M_QUIETZONE => '#FFFFFF', + ], +]); + + header('Content-Type: text/html; charset=utf-8'); ?> @@ -23,7 +57,7 @@ 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); + echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); ?> -
- - - diff --git a/examples/image.php b/examples/image.php index 4ca59b099..7bd5c2f84 100644 --- a/examples/image.php +++ b/examples/image.php @@ -1,7 +1,5 @@ * @copyright 2017 Smiley @@ -9,11 +7,10 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Data\QRMatrix; require_once __DIR__.'/../vendor/autoload.php'; -$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; - $options = new QROptions([ 'version' => 10, 'outputType' => QRCode::OUTPUT_IMAGE_PNG, @@ -22,40 +19,36 @@ $options = new QROptions([ '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 - 5632 => [241, 28, 163], // finder dot, dark (true) + (QRMatrix::M_FINDER << 8) => [0, 63, 255], // dark (true) + (QRMatrix::M_FINDER_DOT << 8) => [241, 28, 163], // finder dot, dark (true) + QRMatrix::M_FINDER => [255, 255, 255], // light (false), white is the transparency color and is enabled by default // alignment - 2560 => [255, 0, 255], - 10 => [255, 255, 255], + (QRMatrix::M_ALIGNMENT << 8) => [255, 0, 255], + QRMatrix::M_ALIGNMENT => [255, 255, 255], // timing - 3072 => [255, 0, 0], - 12 => [255, 255, 255], + (QRMatrix::M_TIMING << 8) => [255, 0, 0], + QRMatrix::M_TIMING => [255, 255, 255], // format - 3584 => [67, 99, 84], - 14 => [255, 255, 255], + (QRMatrix::M_FORMAT << 8) => [67, 99, 84], + QRMatrix::M_FORMAT => [255, 255, 255], // version - 4096 => [62, 174, 190], - 16 => [255, 255, 255], + (QRMatrix::M_VERSION << 8) => [62, 174, 190], + QRMatrix::M_VERSION => [255, 255, 255], // data - 1024 => [0, 0, 0], - 4 => [255, 255, 255], + (QRMatrix::M_DATA << 8) => [0, 0, 0], + QRMatrix::M_DATA => [255, 255, 255], // darkmodule - 512 => [0, 0, 0], + (QRMatrix::M_DARKMODULE << 8) => [0, 0, 0], // separator - 8 => [255, 255, 255], + QRMatrix::M_SEPARATOR => [255, 255, 255], // quietzone - 18 => [255, 255, 255], + QRMatrix::M_QUIETZONE => [255, 255, 255], // logo (requires a call to QRMatrix::setLogoSpace()) - 20 => [255, 255, 255], + QRMatrix::M_LOGO => [255, 255, 255], ], ]); + header('Content-type: image/png'); -echo (new QRCode($options))->render($data); - - - - - +echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); diff --git a/examples/imageWithLogo.php b/examples/imageWithLogo.php index 29314ae94..b178d5077 100644 --- a/examples/imageWithLogo.php +++ b/examples/imageWithLogo.php @@ -1,18 +1,77 @@ * @copyright 2020 smiley * @license MIT + * + * @noinspection PhpComposerExtensionStubsInspection */ use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Output\{QRCodeOutputException, QRImage}; require_once __DIR__.'/../vendor/autoload.php'; -$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; +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; + } + +} + /** * @property int $logoSpaceWidth @@ -24,6 +83,7 @@ class LogoOptions extends QROptions{ protected int $logoSpaceHeight; } + $options = new LogoOptions; $options->version = 7; @@ -34,9 +94,10 @@ $options->logoSpaceHeight = 13; $options->scale = 5; $options->imageTransparent = false; + header('Content-type: image/png'); -$qrOutputInterface = new QRImageWithLogo($options, (new QRCode($options))->getMatrix($data)); +$qrOutputInterface = new QRImageWithLogo($options, (new QRCode($options))->getMatrix('https://www.youtube.com/watch?v=dQw4w9WgXcQ')); // dump the output, with an additional logo echo $qrOutputInterface->dump(null, __DIR__.'/octocat.png'); diff --git a/examples/imageWithText.php b/examples/imageWithText.php index ded2bb59c..c366eaaff 100644 --- a/examples/imageWithText.php +++ b/examples/imageWithText.php @@ -3,18 +3,95 @@ * example for additional text * @link https://github.com/chillerlan/php-qrcode/issues/35 * - * @filesource imageWithText.php * @created 22.06.2019 * @author Smiley * @copyright 2019 Smiley * @license MIT + * + * @noinspection PhpComposerExtensionStubsInspection */ use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Output\QRImage; require_once __DIR__.'/../vendor/autoload.php'; -$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; +class QRImageWithText extends QRImage{ + + /** + * @param string|null $file + * @param string|null $text + * + * @return string + */ + public function dump(string $file = null, string $text = null):string{ + // set returnResource to true to skip further processing for now + $this->options->returnResource = true; + + // there's no need to save the result of dump() into $this->image here + parent::dump($file); + + // render text output if a string is given + if($text !== null){ + $this->addText($text); + } + + $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; + } + + /** + * @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($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, (int)($i * $w + $x), $this->length, $chr, $fontColor); + } + } + +} + $options = new QROptions([ 'version' => 7, @@ -23,9 +100,10 @@ $options = new QROptions([ 'imageBase64' => false, ]); + header('Content-type: image/png'); -$qrOutputInterface = new QRImageWithText($options, (new QRCode($options))->getMatrix($data)); +$qrOutputInterface = new QRImageWithText($options, (new QRCode($options))->getMatrix('https://www.youtube.com/watch?v=dQw4w9WgXcQ')); // dump the output, with additional text echo $qrOutputInterface->dump(null, 'example text'); diff --git a/examples/imagick.php b/examples/imagick.php index 0c3168151..6329b8e4a 100644 --- a/examples/imagick.php +++ b/examples/imagick.php @@ -1,7 +1,5 @@ * @copyright 2017 Smiley @@ -9,11 +7,10 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Data\QRMatrix; 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, @@ -21,37 +18,34 @@ $options = new QROptions([ 'scale' => 5, 'moduleValues' => [ // finder - 1536 => '#A71111', // dark (true) - 6 => '#FFBFBF', // light (false) + (QRMatrix::M_FINDER << 8) => '#A71111', // dark (true) + (QRMatrix::M_FINDER_DOT << 8) => '#A71111', + QRMatrix::M_FINDER => '#FFBFBF', // light (false) // alignment - 2560 => '#A70364', - 10 => '#FFC9C9', + (QRMatrix::M_ALIGNMENT << 8) => '#A70364', + QRMatrix::M_ALIGNMENT => '#FFC9C9', // timing - 3072 => '#98005D', - 12 => '#FFB8E9', + (QRMatrix::M_TIMING << 8) => '#98005D', + QRMatrix::M_TIMING => '#FFB8E9', // format - 3584 => '#003804', - 14 => '#00FB12', + (QRMatrix::M_FORMAT << 8) => '#003804', + QRMatrix::M_FORMAT => '#00FB12', // version - 4096 => '#650098', - 16 => '#E0B8FF', + (QRMatrix::M_VERSION << 8) => '#650098', + QRMatrix::M_VERSION => '#E0B8FF', // data - 1024 => '#4A6000', - 4 => '#ECF9BE', + (QRMatrix::M_DATA << 8) => '#4A6000', + QRMatrix::M_DATA => '#ECF9BE', // darkmodule - 512 => '#080063', + (QRMatrix::M_DARKMODULE << 8) => '#080063', // separator - 8 => '#DDDDDD', + QRMatrix::M_SEPARATOR => '#DDDDDD', // quietzone - 18 => '#DDDDDD', + QRMatrix::M_QUIETZONE => '#DDDDDD', ], ]); + header('Content-type: image/png'); -echo (new QRCode($options))->render($data); - - - - - +echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); diff --git a/examples/qrcode-interactive.php b/examples/qrcode-interactive.php index 6f105cbfc..93c0d7159 100644 --- a/examples/qrcode-interactive.php +++ b/examples/qrcode-interactive.php @@ -1,6 +1,5 @@ * @copyright 2017 Smiley @@ -9,8 +8,8 @@ * @noinspection PhpComposerExtensionStubsInspection */ -use chillerlan\QRCode\QRCode; -use chillerlan\QRCode\QROptions; +use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Data\QRMatrix; require_once '../vendor/autoload.php'; @@ -18,29 +17,30 @@ try{ $moduleValues = [ // finder - 1536 => $_POST['m_finder_dark'], - 6 => $_POST['m_finder_light'], + (QRMatrix::M_FINDER << 8) => $_POST['m_finder_dark'], + (QRMatrix::M_FINDER_DOT << 8) => $_POST['m_finder_dark'], + QRMatrix::M_FINDER => $_POST['m_finder_light'], // alignment - 2560 => $_POST['m_alignment_dark'], - 10 => $_POST['m_alignment_light'], + (QRMatrix::M_ALIGNMENT << 8) => $_POST['m_alignment_dark'], + QRMatrix::M_ALIGNMENT => $_POST['m_alignment_light'], // timing - 3072 => $_POST['m_timing_dark'], - 12 => $_POST['m_timing_light'], + (QRMatrix::M_TIMING << 8) => $_POST['m_timing_dark'], + QRMatrix::M_TIMING => $_POST['m_timing_light'], // format - 3584 => $_POST['m_format_dark'], - 14 => $_POST['m_format_light'], + (QRMatrix::M_FORMAT << 8) => $_POST['m_format_dark'], + QRMatrix::M_FORMAT => $_POST['m_format_light'], // version - 4096 => $_POST['m_version_dark'], - 16 => $_POST['m_version_light'], + (QRMatrix::M_VERSION << 8) => $_POST['m_version_dark'], + QRMatrix::M_VERSION => $_POST['m_version_light'], // data - 1024 => $_POST['m_data_dark'], - 4 => $_POST['m_data_light'], + (QRMatrix::M_DATA << 8) => $_POST['m_data_dark'], + QRMatrix::M_DATA => $_POST['m_data_light'], // darkmodule - 512 => $_POST['m_darkmodule_dark'], + (QRMatrix::M_DARKMODULE << 8) => $_POST['m_darkmodule_dark'], // separator - 8 => $_POST['m_separator_light'], + QRMatrix::M_SEPARATOR => $_POST['m_separator_light'], // quietzone - 18 => $_POST['m_quietzone_light'], + QRMatrix::M_QUIETZONE => $_POST['m_quietzone_light'], ]; $moduleValues = array_map(function($v){ diff --git a/examples/svg.php b/examples/svg.php index d823bcf8a..da6a5cac4 100644 --- a/examples/svg.php +++ b/examples/svg.php @@ -1,18 +1,18 @@ * @copyright 2017 Smiley * @license MIT + * + * @noinspection PhpComposerExtensionStubsInspection */ use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Data\QRMatrix; require_once __DIR__.'/../vendor/autoload.php'; -$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; $gzip = true; $options = new QROptions([ @@ -22,7 +22,6 @@ $options = new QROptions([ 'eccLevel' => QRCode::ECC_L, 'svgViewBoxSize' => 530, 'addQuietzone' => true, - 'cssClass' => 'my-css-class', 'svgOpacity' => 1.0, 'svgDefs' => ' @@ -36,41 +35,42 @@ $options = new QROptions([ ', 'moduleValues' => [ // finder - 1536 => 'url(#g1)', // dark (true) - 6 => '#fff', // light (false) + (QRMatrix::M_FINDER << 8) => 'url(#g1)', // dark (true) + (QRMatrix::M_FINDER_DOT << 8) => 'url(#g1)', + QRMatrix::M_FINDER => '#fff', // light (false) // alignment - 2560 => 'url(#g1)', - 10 => '#fff', + (QRMatrix::M_ALIGNMENT << 8) => 'url(#g1)', + QRMatrix::M_ALIGNMENT => '#fff', // timing - 3072 => 'url(#g1)', - 12 => '#fff', + (QRMatrix::M_TIMING << 8) => 'url(#g1)', + QRMatrix::M_TIMING => '#fff', // format - 3584 => 'url(#g1)', - 14 => '#fff', + (QRMatrix::M_FORMAT << 8) => 'url(#g1)', + QRMatrix::M_FORMAT => '#fff', // version - 4096 => 'url(#g1)', - 16 => '#fff', + (QRMatrix::M_VERSION << 8) => 'url(#g1)', + QRMatrix::M_VERSION => '#fff', // data - 1024 => 'url(#g2)', - 4 => '#fff', + (QRMatrix::M_DATA << 8) => 'url(#g2)', + QRMatrix::M_DATA => '#fff', // darkmodule - 512 => 'url(#g1)', + (QRMatrix::M_DARKMODULE << 8) => 'url(#g1)', // separator - 8 => '#fff', + QRMatrix::M_SEPARATOR => '#fff', // quietzone - 18 => '#fff', + QRMatrix::M_QUIETZONE => '#fff', ], ]); -$qrcode = (new QRCode($options))->render($data); + +$qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); header('Content-type: image/svg+xml'); if($gzip === true){ header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); - $qrcode = gzencode($qrcode ,9); + $qrcode = gzencode($qrcode , 9); } + echo $qrcode; - - diff --git a/examples/text.php b/examples/text.php index 950d02d24..ef5191586 100644 --- a/examples/text.php +++ b/examples/text.php @@ -1,7 +1,5 @@ * @copyright 2017 Smiley @@ -9,58 +7,44 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Data\QRMatrix; 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) + (QRMatrix::M_FINDER << 8) => 'A', // dark (true) + (QRMatrix::M_FINDER_DOT << 8) => 'A', // dark (true) + QRMatrix::M_FINDER => 'a', // light (false) // alignment - 2560 => 'B', - 10 => 'b', + (QRMatrix::M_ALIGNMENT << 8) => 'B', + QRMatrix::M_ALIGNMENT => 'b', // timing - 3072 => 'C', - 12 => 'c', + (QRMatrix::M_TIMING << 8) => 'C', + QRMatrix::M_TIMING => 'c', // format - 3584 => 'D', - 14 => 'd', + (QRMatrix::M_FORMAT << 8) => 'D', + QRMatrix::M_FORMAT => 'd', // version - 4096 => 'E', - 16 => 'e', + (QRMatrix::M_VERSION << 8) => 'E', + QRMatrix::M_VERSION => 'e', // data - 1024 => 'F', - 4 => 'f', + (QRMatrix::M_DATA << 8) => 'F', + QRMatrix::M_DATA => 'f', // darkmodule - 512 => 'G', + (QRMatrix::M_DARKMODULE << 8) => 'G', // separator - 8 => 'h', + QRMatrix::M_SEPARATOR => 'h', // quietzone - 18 => 'i', + QRMatrix::M_QUIETZONE => 'x', ], ]); //
 to view it in a browser
-echo '
'.(new QRCode($options))->render($data).'
'; - - - - +$qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); +echo '
'.$qrcode.'
'; diff --git a/tests/Output/QRStringTest.php b/tests/Output/QRStringTest.php index c41d109be..a9590a34b 100644 --- a/tests/Output/QRStringTest.php +++ b/tests/Output/QRStringTest.php @@ -12,7 +12,6 @@ namespace chillerlan\QRCodeTest\Output; -use chillerlan\QRCodeExamples\MyCustomOutput; use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Output\{QROutputInterface, QRString}; @@ -58,19 +57,4 @@ class QRStringTest extends QROutputTestAbstract{ $this::assertStringContainsString('B', $data); } - /** - * covers the custom output functionality via an example - */ - public function testCustomOutput():void{ - $this->options->version = 5; - $this->options->eccLevel = QRCode::ECC_L; - $this->options->outputType = QRCode::OUTPUT_CUSTOM; - $this->options->outputInterface = MyCustomOutput::class; - - $this::assertSame( - file_get_contents(__DIR__.'/samples/custom'), - (new QRCode($this->options))->render('test') - ); - } - }