🚿 examples cleanup

This commit is contained in:
smiley
2023-03-12 02:16:38 +01:00
parent 11d696ee39
commit 6b92bb4c6f
14 changed files with 351 additions and 443 deletions
-36
View File
@@ -1,36 +0,0 @@
<?php
/**
* Class MyCustomOutput
*
* @filesource MyCustomOutput.php
* @created 24.12.2017
* @package chillerlan\QRCodeExamples
* @author Smiley <smiley@chillerlan.net>
* @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;
}
}
-76
View File
@@ -1,76 +0,0 @@
<?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
*/
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;
}
}
-98
View File
@@ -1,98 +0,0 @@
<?php
/**
* Class QRImageWithText
*
* example for additional text
*
* @link https://github.com/chillerlan/php-qrcode/issues/35
*
* @filesource QRImageWithText.php
* @created 22.06.2019
* @package chillerlan\QRCodeExamples
* @author smiley <smiley@chillerlan.net>
* @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);
}
}
}
+27 -4
View File
@@ -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 '<pre>'.$qrOutputInterface->dump().'</pre>';
// or just
@@ -33,4 +56,4 @@ $options = new QROptions([
'outputInterface' => MyCustomOutput::class,
]);
var_dump((new QRCode($options))->render($data));
echo '<pre>'.(new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ').'</pre>';
+41 -35
View File
@@ -1,45 +1,51 @@
<?php
/**
* @created 03.06.2020
* @author Maximilian Kresse
* @license MIT
*/
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_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');
+38 -43
View File
@@ -1,7 +1,5 @@
<?php
/**
*
* @filesource html.php
* @created 21.12.2017
* @author Smiley <smiley@chillerlan.net>
* @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');
<title>QRCode test</title>
<style>
body{
margin: 5em;
margin: 1em;
padding: 0;
}
@@ -52,49 +86,10 @@ header('Content-Type: text/html; charset=utf-8');
</style>
</head>
<body>
<div class="qrcode">
<?php
$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
$options = new QROptions([
'version' => 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');
?>
</div>
</body>
</html>
+20 -27
View File
@@ -1,7 +1,5 @@
<?php
/**
*
* @filesource image.php
* @created 24.12.2017
* @author Smiley <smiley@chillerlan.net>
* @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');
+65 -4
View File
@@ -1,18 +1,77 @@
<?php
/**
*
* @filesource imageWithLogo.php
* @created 18.11.2020
* @author smiley <smiley@chillerlan.net>
* @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');
+81 -3
View File
@@ -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 <smiley@chillerlan.net>
* @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');
+19 -25
View File
@@ -1,7 +1,5 @@
<?php
/**
*
* @filesource image.php
* @created 24.12.2017
* @author Smiley <smiley@chillerlan.net>
* @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');
+18 -18
View File
@@ -1,6 +1,5 @@
<?php
/**
* @filesource qrcode.php
* @created 18.11.2017
* @author Smiley <smiley@chillerlan.net>
* @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){
+23 -23
View File
@@ -1,18 +1,18 @@
<?php
/**
*
* @filesource svg.php
* @created 21.12.2017
* @author Smiley <smiley@chillerlan.net>
* @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' => '
<linearGradient id="g2">
@@ -36,41 +35,42 @@ $options = new QROptions([
<style>rect{shape-rendering:crispEdges}</style>',
'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;
+19 -35
View File
@@ -1,7 +1,5 @@
<?php
/**
*
* @filesource text.php
* @created 21.12.2017
* @author Smiley <smiley@chillerlan.net>
* @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,
]);
// <pre> to view it in a browser
echo '<pre style="font-size: 75%; line-height: 1;">'.(new QRCode($options))->render($data).'</pre>';
// 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',
],
]);
// <pre> to view it in a browser
echo '<pre style="font-size: 75%; line-height: 1;">'.(new QRCode($options))->render($data).'</pre>';
$qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
echo '<pre style="line-height: 1;">'.$qrcode.'</pre>';
-16
View File
@@ -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')
);
}
}