From 3d2f908d240a64c85496ffc8b8ce40e8e5cf2d2d Mon Sep 17 00:00:00 2001 From: smiley Date: Sun, 24 Dec 2017 08:09:19 +0100 Subject: [PATCH] :sparkles: more examples --- examples/MyCustomOutput.php | 34 +++++++++++++++++++++ examples/custom_output.php | 26 ++++++++++++++++ examples/html.php | 2 ++ examples/image.php | 60 +++++++++++++++++++++++++++++++++++++ examples/svg.php | 2 ++ examples/text.php | 39 ++++++++++++++++++++++++ 6 files changed, 163 insertions(+) create mode 100644 examples/MyCustomOutput.php create mode 100644 examples/custom_output.php create mode 100644 examples/image.php diff --git a/examples/MyCustomOutput.php b/examples/MyCustomOutput.php new file mode 100644 index 000000000..53133b4b1 --- /dev/null +++ b/examples/MyCustomOutput.php @@ -0,0 +1,34 @@ + + * @copyright 2017 Smiley + * @license MIT + */ + +namespace chillerlan\QRCodeExamples; + +use chillerlan\QRCode\Output\QROutputAbstract; + +/** + */ +class MyCustomOutput extends QROutputAbstract{ + + public function dump(){ + + $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/examples/custom_output.php b/examples/custom_output.php new file mode 100644 index 000000000..54cda1e6b --- /dev/null +++ b/examples/custom_output.php @@ -0,0 +1,26 @@ + + * @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, + 'eccLevel' => QRCode::ECC_L, +]); + +$qrOutputInterface = new MyCustomOutput($options, (new QRCode($options))->getMatrix($data)); + +var_dump($qrOutputInterface->dump()); diff --git a/examples/html.php b/examples/html.php index 6e89d3410..1d1ff03a0 100644 --- a/examples/html.php +++ b/examples/html.php @@ -8,6 +8,8 @@ * @license MIT */ +namespace chillerlan\QRCodeExamples; + use chillerlan\QRCode\{QRCode, QROptions}; require_once '../vendor/autoload.php'; diff --git a/examples/image.php b/examples/image.php new file mode 100644 index 000000000..a650c6fd9 --- /dev/null +++ b/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' => 5, + 'outputType' => QRCode::OUTPUT_IMAGE_PNG, + 'eccLevel' => QRCode::ECC_L, + 'scale' => 10, + 'imageBase64' => false, + 'moduleValues' => [ + // finder + 1536 => [255, 0, 0], // dark (true) + 6 => [255, 255, 255], // light (false), white is the transparency color and is enabled by default + // alignment + 2560 => [255, 0, 0], + 10 => [255, 255, 255], + // timing + 3072 => [0, 0, 0], + 12 => [200, 200, 200], + // format + 3584 => [0, 0, 0], + 14 => [200, 200, 200], + // version + 4096 => [0, 0, 0], + 16 => [200, 200, 200], + // data + 1024 => [0, 0, 150], + 4 => [255, 255, 255], + // darkmodule + 512 => [0, 0, 0], + // separator + 8 => [200, 200, 200], + // quietzone + 18 => [255, 255, 255], + ], +]); + +header('Content-type: image/png'); + +echo (new QRCode($options))->render($data); + + + + + diff --git a/examples/svg.php b/examples/svg.php index 0488141b9..3c837e324 100644 --- a/examples/svg.php +++ b/examples/svg.php @@ -8,6 +8,8 @@ * @license MIT */ +namespace chillerlan\QRCodeExamples; + use chillerlan\QRCode\{QRCode, QROptions}; require_once __DIR__.'/../vendor/autoload.php'; diff --git a/examples/text.php b/examples/text.php index 19e45324a..9bdf154f0 100644 --- a/examples/text.php +++ b/examples/text.php @@ -8,6 +8,8 @@ * @license MIT */ +namespace chillerlan\QRCodeExamples; + use chillerlan\QRCode\{QRCode, QROptions}; require_once __DIR__.'/../vendor/autoload.php'; @@ -24,6 +26,43 @@ $options = new QROptions([ 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).'
'; + +