🛀 examples cleanup

This commit is contained in:
smiley
2023-09-03 15:29:24 +02:00
parent 17e8ccae62
commit a19b7f4fbd
19 changed files with 571 additions and 539 deletions
+35 -37
View File
@@ -1,6 +1,6 @@
<?php
/**
* authenticator.php
* authenticator excample
*
* @created 09.07.2023
* @author smiley <smiley@chillerlan.net>
@@ -16,48 +16,46 @@ use chillerlan\QRCode\Data\QRMatrix;
require_once __DIR__.'/../vendor/autoload.php';
// the options array
$optionsArray = [
/*
* AuthenticatorOptionsTrait
*
* @see https://github.com/chillerlan/php-authenticator
*/
'mode' => AuthenticatorInterface::TOTP,
'digits' => 8,
'algorithm' => AuthenticatorInterface::ALGO_SHA512,
// create a new options container on the fly that hosts both, authenticator and qrcode
$options = new class extends SettingsContainerAbstract{
use AuthenticatorOptionsTrait, QROptionsTrait;
};
/*
* QROptionsTrait
*/
'version' => 7,
'addQuietzone' => false,
'imageBase64' => false,
'svgAddXmlHeader' => false,
'cssClass' => 'my-qrcode',
'drawLightModules' => false,
'markupDark' => '',
'markupLight' => '',
'drawCircularModules' => true,
'circleRadius' => 0.4,
'connectPaths' => true,
'keepAsSquare' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
],
'svgDefs' => '
/*
* AuthenticatorOptionsTrait
*
* @see https://github.com/chillerlan/php-authenticator
*/
$options->mode = AuthenticatorInterface::TOTP;
$options->digits = 8;
$options->algorithm = AuthenticatorInterface::ALGO_SHA512;
/*
* QROptionsTrait
*/
$options->version = 7;
$options->addQuietzone = false;
$options->imageBase64 = false;
$options->svgAddXmlHeader = false;
$options->cssClass = 'my-qrcode';
$options->drawLightModules = false;
$options->markupDark = '';
$options->markupLight = '';
$options->drawCircularModules = true;
$options->circleRadius = 0.4;
$options->connectPaths = true;
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
$options->svgDefs = '
<linearGradient id="gradient" x1="1" y2="1">
<stop id="stop1" offset="0" />
<stop id="stop2" offset="0.5"/>
<stop id="stop3" offset="1"/>
</linearGradient>',
];
</linearGradient>';
// create a new options container on the fly that hosts both, authenticator and qrcode
$options = new class($optionsArray) extends SettingsContainerAbstract{
use AuthenticatorOptionsTrait, QROptionsTrait;
};
// invoke the worker instances
$authenticator = new Authenticator($options);
+10 -12
View File
@@ -1,5 +1,7 @@
<?php
/**
* custom output example
*
* @created 24.12.2017
* @author Smiley <smiley@chillerlan.net>
* @copyright 2017 Smiley
@@ -24,7 +26,7 @@ class MyCustomOutput extends QROutputAbstract{
* @inheritDoc
*/
public static function moduleValueIsValid($value):bool{
// TODO: Implement moduleValueIsValid() method. (abstract)
// TODO: Implement moduleValueIsValid() method. (interface)
return false;
}
@@ -68,15 +70,16 @@ class MyCustomOutput extends QROutputAbstract{
* Runtime
*/
$options = new QROptions;
$options->version = 5;
$options->eccLevel = EccLevel::L;
$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
// invoke the QROutputInterface manually
// please note that an QROutputInterface invoked this way might become unusable after calling dump().
// the clean way would be to extend the QRCode class to ensure a new QROutputInterface instance on each call to render().
$options = new QROptions([
'version' => 5,
'eccLevel' => EccLevel::L,
]);
$qrcode = new QRCode($options);
$qrcode->addByteSegment($data);
@@ -85,14 +88,9 @@ $qrOutputInterface = new MyCustomOutput($options, $qrcode->getQRMatrix());
var_dump($qrOutputInterface->dump());
// or just via the options
$options = new QROptions([
'version' => 5,
'eccLevel' => EccLevel::L,
'outputType' => QROutputInterface::CUSTOM,
'outputInterface' => MyCustomOutput::class,
]);
$options->outputType = QROutputInterface::CUSTOM;
$options->outputInterface = MyCustomOutput::class;
var_dump((new QRCode($options))->render($data));
+7 -2
View File
@@ -1,5 +1,7 @@
<?php
/**
* EPS output example
*
* @created 10.05.2022
* @author Smiley <smiley@chillerlan.net>
* @copyright 2022 Smiley
@@ -18,6 +20,7 @@ $options->version = 7;
$options->outputType = QROutputInterface::EPS;
$options->scale = 5;
$options->drawLightModules = false;
// colors can be specified either as [R, G, B] or [C, M, Y, K] (0-255)
$options->bgColor = [222, 222, 222];
$options->moduleValues = [
// finder
@@ -45,17 +48,19 @@ $options->moduleValues = [
QRMatrix::M_SEPARATOR => [233, 233, 233],
// quietzone
QRMatrix::M_QUIETZONE => [233, 233, 233],
// logo (requires a call to QRMatrix::setLogoSpace()), see QRImageWithLogo
// logo space (requires a call to QRMatrix::setLogoSpace()), see imageWithLogo example
QRMatrix::M_LOGO => [233, 233, 233],
];
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ', __DIR__.'/qrcode.eps');
if(php_sapi_name() !== 'cli'){
// if viewed in the browser, we should push it as file download as EPS isn't usually supported
header('Content-type: application/postscript');
header('Content-Disposition: filename="qrcode.eps"');
}
echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ', __DIR__.'/test.eps');
echo $out;
exit;
+42 -38
View File
@@ -1,58 +1,62 @@
<?php
/**
* FPDF output example
*
* @created 03.06.2020
* @author Maximilian Kresse
* @license MIT
*/
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Common\EccLevel;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\QROutputInterface;
require_once __DIR__ . '/../vendor/autoload.php';
$options = new QROptions([
'version' => 7,
'outputType' => QROutputInterface::FPDF,
'eccLevel' => EccLevel::L,
'scale' => 5,
'bgColor' => [234, 234, 234],
'drawLightModules' => false,
'imageBase64' => false,
'moduleValues' => [
// finder
QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
QRMatrix::M_FINDER_DOT => [0, 63, 255], // finder dot, dark (true)
QRMatrix::M_FINDER => [255, 255, 255], // light (false), white is the transparency color and is enabled by default
// alignment
QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
QRMatrix::M_ALIGNMENT => [255, 255, 255],
// timing
QRMatrix::M_TIMING_DARK => [255, 0, 0],
QRMatrix::M_TIMING => [255, 255, 255],
// format
QRMatrix::M_FORMAT_DARK => [67, 191, 84],
QRMatrix::M_FORMAT => [255, 255, 255],
// version
QRMatrix::M_VERSION_DARK => [62, 174, 190],
QRMatrix::M_VERSION => [255, 255, 255],
// data
QRMatrix::M_DATA_DARK => [0, 0, 0],
QRMatrix::M_DATA => [255, 255, 255],
// darkmodule
QRMatrix::M_DARKMODULE => [0, 0, 0],
// separator
QRMatrix::M_SEPARATOR => [255, 255, 255],
// quietzone
QRMatrix::M_QUIETZONE => [255, 255, 255],
],
]);
$options = new QROptions;
$options->version = 7;
$options->outputType = QROutputInterface::FPDF;
$options->scale = 5;
$options->fpdfMeasureUnit = 'mm';
$options->bgColor = [222, 222, 222];
$options->drawLightModules = false;
$options->imageBase64 = false;
$options->moduleValues = [
// finder
QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
QRMatrix::M_FINDER_DOT => [0, 63, 255], // finder dot, dark (true)
QRMatrix::M_FINDER => [255, 255, 255], // light (false)
// alignment
QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
QRMatrix::M_ALIGNMENT => [255, 255, 255],
// timing
QRMatrix::M_TIMING_DARK => [255, 0, 0],
QRMatrix::M_TIMING => [255, 255, 255],
// format
QRMatrix::M_FORMAT_DARK => [67, 191, 84],
QRMatrix::M_FORMAT => [255, 255, 255],
// version
QRMatrix::M_VERSION_DARK => [62, 174, 190],
QRMatrix::M_VERSION => [255, 255, 255],
// data
QRMatrix::M_DATA_DARK => [0, 0, 0],
QRMatrix::M_DATA => [255, 255, 255],
// darkmodule
QRMatrix::M_DARKMODULE => [0, 0, 0],
// separator
QRMatrix::M_SEPARATOR => [255, 255, 255],
// quietzone
QRMatrix::M_QUIETZONE => [255, 255, 255],
];
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
if(php_sapi_name() !== 'cli'){
header('Content-type: application/pdf');
}
echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
echo $out;
exit;
+24 -41
View File
@@ -1,5 +1,7 @@
<?php
/**
* HTML output example
*
* @created 21.12.2017
* @author Smiley <smiley@chillerlan.net>
* @copyright 2017 Smiley
@@ -7,47 +9,32 @@
*/
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Common\EccLevel;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\QROutputInterface;
require_once '../vendor/autoload.php';
header('Content-Type: text/html; charset=utf-8');
$options = new QROptions;
$options = new QROptions([
'version' => 5,
'outputType' => QROutputInterface::MARKUP_HTML,
'eccLevel' => EccLevel::L,
'cssClass' => 'qrcode',
'moduleValues' => [
// finder
QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
QRMatrix::M_FINDER => '#FFBFBF', // light (false)
// alignment
QRMatrix::M_ALIGNMENT_DARK => '#A70364',
QRMatrix::M_ALIGNMENT => '#FFC9C9',
// timing
QRMatrix::M_TIMING_DARK => '#98005D',
QRMatrix::M_TIMING => '#FFB8E9',
// format
QRMatrix::M_FORMAT_DARK => '#003804',
QRMatrix::M_FORMAT => '#00FB12',
// version
QRMatrix::M_VERSION_DARK => '#650098',
QRMatrix::M_VERSION => '#E0B8FF',
// data
QRMatrix::M_DATA_DARK => '#4A6000',
QRMatrix::M_DATA => '#ECF9BE',
// darkmodule
QRMatrix::M_DARKMODULE => '#080063',
// separator
QRMatrix::M_SEPARATOR => '#AFBFBF',
// quietzone
QRMatrix::M_QUIETZONE => '#DDDDDD',
],
]);
$options->version = 5;
$options->outputType = QROutputInterface::MARKUP_HTML;
$options->cssClass = 'qrcode';
$options->markupDark = '#555';
$options->markupLight = '#CCC';
$options->moduleValues = [
// finder
QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
QRMatrix::M_FINDER => '#FFBFBF', // light (false)
// alignment
QRMatrix::M_ALIGNMENT_DARK => '#A70364',
QRMatrix::M_ALIGNMENT => '#FFC9C9',
];
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
@@ -55,7 +42,7 @@ header('Content-Type: text/html; charset=utf-8');
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>QRCode test</title>
<title>QRCode HTML Example</title>
<style>
div.qrcode{
margin: 1em;
@@ -75,10 +62,6 @@ header('Content-Type: text/html; charset=utf-8');
</style>
</head>
<body>
<?php
echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
?>
<?php echo $out; ?>
</body>
</html>
+49 -54
View File
@@ -1,5 +1,7 @@
<?php
/**
* GdImage output example
*
* @created 24.12.2017
* @author Smiley <smiley@chillerlan.net>
* @copyright 2017 Smiley
@@ -7,67 +9,60 @@
*/
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Common\EccLevel;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\QROutputInterface;
require_once __DIR__.'/../vendor/autoload.php';
$options = new QROptions([
'version' => 7,
'outputType' => QROutputInterface::GDIMAGE_PNG,
'eccLevel' => EccLevel::L,
'scale' => 20,
'imageBase64' => false,
'bgColor' => [200, 150, 200],
'imageTransparent' => true,
# 'transparencyColor' => [233, 233, 233],
'drawCircularModules' => true,
'drawLightModules' => true,
'circleRadius' => 0.4,
'keepAsSquare' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
],
'moduleValues' => [
// finder
QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
QRMatrix::M_FINDER_DOT => [0, 63, 255], // finder dot, dark (true)
QRMatrix::M_FINDER => [233, 233, 233], // light (false), white is the transparency color and is enabled by default
// alignment
QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
QRMatrix::M_ALIGNMENT => [233, 233, 233],
// timing
QRMatrix::M_TIMING_DARK => [255, 0, 0],
QRMatrix::M_TIMING => [233, 233, 233],
// format
QRMatrix::M_FORMAT_DARK => [67, 159, 84],
QRMatrix::M_FORMAT => [233, 233, 233],
// version
QRMatrix::M_VERSION_DARK => [62, 174, 190],
QRMatrix::M_VERSION => [233, 233, 233],
// data
QRMatrix::M_DATA_DARK => [0, 0, 0],
QRMatrix::M_DATA => [233, 233, 233],
// darkmodule
QRMatrix::M_DARKMODULE => [0, 0, 0],
// separator
QRMatrix::M_SEPARATOR => [233, 233, 233],
// quietzone
QRMatrix::M_QUIETZONE => [233, 233, 233],
// logo (requires a call to QRMatrix::setLogoSpace()), see QRImageWithLogo
QRMatrix::M_LOGO => [233, 233, 233],
],
]);
$options = new QROptions;
$options->version = 7;
$options->outputType = QROutputInterface::GDIMAGE_PNG;
$options->scale = 20;
$options->imageBase64 = false;
$options->bgColor = [200, 150, 200];
$options->imageTransparent = true;
#$options->transparencyColor = [233, 233, 233];
$options->drawCircularModules = true;
$options->drawLightModules = true;
$options->circleRadius = 0.4;
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
$options->moduleValues = [
// finder
QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
QRMatrix::M_FINDER_DOT => [0, 63, 255], // finder dot, dark (true)
QRMatrix::M_FINDER => [233, 233, 233], // light (false), white is the transparency color and is enabled by default
// alignment
QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
QRMatrix::M_ALIGNMENT => [233, 233, 233],
// timing
QRMatrix::M_TIMING_DARK => [255, 0, 0],
QRMatrix::M_TIMING => [233, 233, 233],
// format
QRMatrix::M_FORMAT_DARK => [67, 159, 84],
QRMatrix::M_FORMAT => [233, 233, 233],
// version
QRMatrix::M_VERSION_DARK => [62, 174, 190],
QRMatrix::M_VERSION => [233, 233, 233],
// data
QRMatrix::M_DATA_DARK => [0, 0, 0],
QRMatrix::M_DATA => [233, 233, 233],
// darkmodule
QRMatrix::M_DARKMODULE => [0, 0, 0],
// separator
QRMatrix::M_SEPARATOR => [233, 233, 233],
// quietzone
QRMatrix::M_QUIETZONE => [233, 233, 233],
// logo (requires a call to QRMatrix::setLogoSpace()), see QRImageWithLogo
QRMatrix::M_LOGO => [233, 233, 233],
];
try{
$im = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
}
catch(Throwable $e){
exit($e->getMessage());
}
$im = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
header('Content-type: image/png');
+27 -16
View File
@@ -1,5 +1,7 @@
<?php
/**
* GdImage with logo output example
*
* @created 18.11.2020
* @author smiley <smiley@chillerlan.net>
* @copyright 2020 smiley
@@ -70,33 +72,42 @@ class QRImageWithLogo extends QRGdImage{
}
/*
* Runtime
*/
$options = new QROptions([
'version' => 5,
'eccLevel' => EccLevel::H,
'imageBase64' => false,
'addLogoSpace' => true,
'logoSpaceWidth' => 13,
'logoSpaceHeight' => 13,
'scale' => 6,
'imageTransparent' => false,
'drawCircularModules' => true,
'circleRadius' => 0.45,
'keepAsSquare' => [QRMatrix::M_FINDER, QRMatrix::M_FINDER_DOT],
]);
$options = new QROptions;
$options->version = 5;
$options->imageBase64 = false;
$options->scale = 6;
$options->imageTransparent = false;
$options->drawCircularModules = true;
$options->circleRadius = 0.45;
$options->keepAsSquare = [
QRMatrix::M_FINDER,
QRMatrix::M_FINDER_DOT,
];
// ecc level H is required for logo space
$options->eccLevel = EccLevel::H;
$options->addLogoSpace = true;
$options->logoSpaceWidth = 13;
$options->logoSpaceHeight = 13;
$qrcode = new QRCode($options);
$qrcode->addByteSegment('https://github.com');
header('Content-type: image/png');
$qrOutputInterface = new QRImageWithLogo($options, $qrcode->getQRMatrix());
// dump the output, with an additional logo
// the logo could also be supplied via the options, see the svgWithLogo example
echo $qrOutputInterface->dump(null, __DIR__.'/octocat.png');
$out = $qrOutputInterface->dump(null, __DIR__.'/octocat.png');
header('Content-type: image/png');
echo $out;
exit;
+16 -10
View File
@@ -1,6 +1,7 @@
<?php
/**
* example for additional text
* GdImage example for displaying additional text under the QR Code
*
* @link https://github.com/chillerlan/php-qrcode/issues/35
*
* @created 22.06.2019
@@ -93,22 +94,27 @@ class QRImageWithText extends QRGdImage{
* Runtime
*/
$options = new QROptions([
'version' => 7,
'outputType' => QROutputInterface::GDIMAGE_PNG,
'scale' => 3,
'imageBase64' => false,
]);
$options = new QROptions;
$options->version = 7;
$options->outputType = QROutputInterface::GDIMAGE_PNG;
$options->scale = 3;
$options->imageBase64 = false;
$qrcode = new QRCode($options);
$qrcode->addByteSegment('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
header('Content-type: image/png');
// invoke the custom output interface manually
$qrOutputInterface = new QRImageWithText($options, $qrcode->getQRMatrix());
// dump the output, with additional text
// the text could also be supplied via the options, see the svgWithLogo example
echo $qrOutputInterface->dump(null, 'example text');
$out = $qrOutputInterface->dump(null, 'example text');
header('Content-type: image/png');
echo $out;
exit;
+51 -47
View File
@@ -1,5 +1,7 @@
<?php
/**
* ImageMagick output example
*
* @created 24.12.2017
* @author Smiley <smiley@chillerlan.net>
* @copyright 2017 Smiley
@@ -7,60 +9,62 @@
*/
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Common\EccLevel;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\QROutputInterface;
require_once __DIR__.'/../vendor/autoload.php';
$options = new QROptions([
'version' => 7,
'outputType' => QROutputInterface::IMAGICK,
'eccLevel' => EccLevel::L,
'scale' => 20,
'imageBase64' => false,
'bgColor' => '#ccccaa',
'imageTransparent' => true,
# 'transparencyColor' => '#ECF9BE',
'drawLightModules' => true,
'drawCircularModules' => true,
'circleRadius' => 0.4,
'keepAsSquare' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
],
'moduleValues' => [
// finder
QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
QRMatrix::M_FINDER => '#FFBFBF', // light (false)
// alignment
QRMatrix::M_ALIGNMENT_DARK => '#A70364',
QRMatrix::M_ALIGNMENT => '#FFC9C9',
// timing
QRMatrix::M_TIMING_DARK => '#98005D',
QRMatrix::M_TIMING => '#FFB8E9',
// format
QRMatrix::M_FORMAT_DARK => '#003804',
QRMatrix::M_FORMAT => '#CCFB12',
// version
QRMatrix::M_VERSION_DARK => '#650098',
QRMatrix::M_VERSION => '#E0B8FF',
// data
QRMatrix::M_DATA_DARK => '#4A6000',
QRMatrix::M_DATA => '#ECF9BE',
// darkmodule
QRMatrix::M_DARKMODULE => '#080063',
// separator
QRMatrix::M_SEPARATOR => '#DDDDDD',
// quietzone
QRMatrix::M_QUIETZONE => '#DDDDDD',
],
]);
$options = new QROptions;
$options->version = 7;
$options->outputType = QROutputInterface::IMAGICK;
$options->scale = 20;
$options->imageBase64 = false;
$options->bgColor = '#ccccaa';
$options->imageTransparent = true;
#$options->transparencyColor = '#ECF9BE';
$options->drawLightModules = true;
$options->drawCircularModules = true;
$options->circleRadius = 0.4;
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
$options->moduleValues = [
// finder
QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
QRMatrix::M_FINDER => '#FFBFBF', // light (false)
// alignment
QRMatrix::M_ALIGNMENT_DARK => '#A70364',
QRMatrix::M_ALIGNMENT => '#FFC9C9',
// timing
QRMatrix::M_TIMING_DARK => '#98005D',
QRMatrix::M_TIMING => '#FFB8E9',
// format
QRMatrix::M_FORMAT_DARK => '#003804',
QRMatrix::M_FORMAT => '#CCFB12',
// version
QRMatrix::M_VERSION_DARK => '#650098',
QRMatrix::M_VERSION => '#E0B8FF',
// data
QRMatrix::M_DATA_DARK => '#4A6000',
QRMatrix::M_DATA => '#ECF9BE',
// darkmodule
QRMatrix::M_DARKMODULE => '#080063',
// separator
QRMatrix::M_SEPARATOR => '#DDDDDD',
// quietzone
QRMatrix::M_QUIETZONE => '#DDDDDD',
];
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
header('Content-type: image/png');
echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
echo $out;
exit;
+29 -24
View File
@@ -1,5 +1,7 @@
<?php
/**
* ImageMagick with logo output example
*
* @created 28.02.2023
* @author Smiley <smiley@chillerlan.net>
* @copyright 2023 Smiley
@@ -92,33 +94,36 @@ class ImagickWithLogoOptions extends QROptions{
* Runtime
*/
$options = new ImagickWithLogoOptions([
'pngLogo' => __DIR__.'/octocat.png', // setting from the augmented options
'version' => 5,
'outputType' => QROutputInterface::CUSTOM,
'outputInterface' => QRImagickWithLogo::class, // use the custom output class
'eccLevel' => EccLevel::H,
'imageBase64' => false,
'addLogoSpace' => true,
'logoSpaceWidth' => 15,
'logoSpaceHeight' => 15,
'bgColor' => '#eee',
'imageTransparent' => true,
'scale' => 20,
'drawLightModules' => false,
'drawCircularModules' => true,
'circleRadius' => 0.4,
'keepAsSquare' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
],
]);
$options = new ImagickWithLogoOptions;
$options->pngLogo = __DIR__.'/octocat.png'; // setting from the augmented options
$options->version = 5;
$options->outputType = QROutputInterface::CUSTOM;
$options->outputInterface = QRImagickWithLogo::class; // use the custom output class
$options->eccLevel = EccLevel::H;
$options->imageBase64 = false;
$options->addLogoSpace = true;
$options->logoSpaceWidth = 15;
$options->logoSpaceHeight = 15;
$options->bgColor = '#eee';
$options->imageTransparent = true;
$options->scale = 20;
$options->drawLightModules = false;
$options->drawCircularModules = true;
$options->circleRadius = 0.4;
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
// dump the output, with an additional logo
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
header('Content-type: image/png');
// dump the output, with an additional logo
echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
echo $out;
exit;
+6 -4
View File
@@ -1,6 +1,6 @@
<?php
/**
* multimode.php
* multi/mixed mode example
*
* @created 31.01.2023
* @author smiley <smiley@chillerlan.net>
@@ -34,7 +34,9 @@ $qrcode = (new QRCode($options))
->addByteSegment('https://www.bundesverfassungsgericht.de/SharedDocs/Pressemitteilungen/DE/2016/bvg16-036.html')
;
$render = $qrcode->render();
$out = $qrcode->render();
if(PHP_SAPI !== 'cli'){
header('Content-type: image/svg+xml');
@@ -42,10 +44,10 @@ if(PHP_SAPI !== 'cli'){
if(extension_loaded('zlib')){
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
$render = gzencode($render, 9);
$out = gzencode($out, 9);
}
}
echo $render;
echo $out;
exit;
+52 -51
View File
@@ -1,6 +1,6 @@
<?php
/**
* reflectance.php
* reflectance reversal example
*
* @created 13.07.2023
* @author smiley <smiley@chillerlan.net>
@@ -16,55 +16,59 @@ use chillerlan\QRCode\QROptions;
require_once __DIR__.'/../vendor/autoload.php';
$options = new QROptions([
'outputType' => QROutputInterface::MARKUP_SVG,
'imageBase64' => false,
'svgAddXmlHeader' => false,
'connectPaths' => true,
'drawCircularModules' => false,
'drawLightModules' => true,
'addLogoSpace' => true,
'eccLevel' => EccLevel::H,
'logoSpaceWidth' => 11,
'moduleValues' => [
// finder
QRMatrix::M_FINDER_DARK => '#555', // dark (true)
QRMatrix::M_FINDER => '#ccc', // light (false)
QRMatrix::M_FINDER_DOT => '#555',
QRMatrix::M_FINDER_DOT_LIGHT => '#ccc',
// alignment
QRMatrix::M_ALIGNMENT_DARK => '#555',
QRMatrix::M_ALIGNMENT => '#ccc',
// timing
QRMatrix::M_TIMING_DARK => '#555',
QRMatrix::M_TIMING => '#ccc',
// format
QRMatrix::M_FORMAT_DARK => '#555',
QRMatrix::M_FORMAT => '#ccc',
// version
QRMatrix::M_VERSION_DARK => '#555',
QRMatrix::M_VERSION => '#ccc',
// data
QRMatrix::M_DATA_DARK => '#555',
QRMatrix::M_DATA => '#ccc',
// darkmodule
QRMatrix::M_DARKMODULE_LIGHT => '#ccc',
QRMatrix::M_DARKMODULE => '#555',
// separator
QRMatrix::M_SEPARATOR_DARK => '#555',
QRMatrix::M_SEPARATOR => '#ccc',
// quietzone
QRMatrix::M_QUIETZONE_DARK => '#555',
QRMatrix::M_QUIETZONE => '#ccc',
// logo space
QRMatrix::M_LOGO_DARK => '#555',
QRMatrix::M_LOGO => '#ccc',
],
]);
$options = new QROptions;
$options->outputType = QROutputInterface::MARKUP_SVG;
$options->imageBase64 = false;
$options->svgAddXmlHeader = false;
$options->connectPaths = true;
$options->drawCircularModules = false;
$options->drawLightModules = true;
$options->addLogoSpace = true;
$options->eccLevel = EccLevel::H;
$options->logoSpaceWidth = 11;
$options->moduleValues = [
// finder
QRMatrix::M_FINDER_DARK => '#555', // dark (true)
QRMatrix::M_FINDER => '#ccc', // light (false)
QRMatrix::M_FINDER_DOT => '#555',
QRMatrix::M_FINDER_DOT_LIGHT => '#ccc',
// alignment
QRMatrix::M_ALIGNMENT_DARK => '#555',
QRMatrix::M_ALIGNMENT => '#ccc',
// timing
QRMatrix::M_TIMING_DARK => '#555',
QRMatrix::M_TIMING => '#ccc',
// format
QRMatrix::M_FORMAT_DARK => '#555',
QRMatrix::M_FORMAT => '#ccc',
// version
QRMatrix::M_VERSION_DARK => '#555',
QRMatrix::M_VERSION => '#ccc',
// data
QRMatrix::M_DATA_DARK => '#555',
QRMatrix::M_DATA => '#ccc',
// darkmodule
QRMatrix::M_DARKMODULE_LIGHT => '#ccc',
QRMatrix::M_DARKMODULE => '#555',
// separator
QRMatrix::M_SEPARATOR_DARK => '#555',
QRMatrix::M_SEPARATOR => '#ccc',
// quietzone
QRMatrix::M_QUIETZONE_DARK => '#555',
QRMatrix::M_QUIETZONE => '#ccc',
// logo space
QRMatrix::M_LOGO_DARK => '#555',
QRMatrix::M_LOGO => '#ccc',
];
$qrcode = (new QRCode($options))->addByteSegment('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
$matrix = $qrcode->getQRMatrix();
$out_normal = $qrcode->renderMatrix($matrix);
$out_inverted = $qrcode->renderMatrix($matrix->invert());
// dump the output
header('Content-type: text/html');
@@ -89,12 +93,9 @@ header('Content-type: text/html');
<div id="reflectance-example">
<!-- embed the SVG directly -->
<?php
echo $qrcode->renderMatrix($matrix);
echo $qrcode->renderMatrix($matrix->invert());
echo $out_normal;
echo $out_inverted;
?>
</div>
</body>
</html>
<?php
exit;
+38 -31
View File
@@ -1,6 +1,7 @@
<?php
/**
* SVG output example
*
* @created 21.12.2017
* @author Smiley <smiley@chillerlan.net>
* @copyright 2017 Smiley
@@ -10,36 +11,34 @@
*/
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Common\EccLevel;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\QROutputInterface;
require_once __DIR__.'/../vendor/autoload.php';
$options = new QROptions([
'version' => 7,
'outputType' => QROutputInterface::MARKUP_SVG,
'imageBase64' => false,
'eccLevel' => EccLevel::L,
'addQuietzone' => true,
// if set to false, the light modules won't be rendered
'drawLightModules' => true,
// empty the default value to remove the fill* and opacity* attributes from the <path> elements
'markupDark' => '',
'markupLight' => '',
// draw the modules as circles isntead of squares
'drawCircularModules' => true,
'circleRadius' => 0.4,
// connect paths
'connectPaths' => true,
// keep modules of these types as square
'keepAsSquare' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
],
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
'svgDefs' => '
$options = new QROptions;
$options->version = 7;
$options->outputType = QROutputInterface::MARKUP_SVG;
$options->imageBase64 = false;
// if set to false, the light modules won't be rendered
$options->drawLightModules = true;
// empty the default value to remove the fill* and opacity* attributes from the <path> elements
$options->markupDark = '';
$options->markupLight = '';
// draw the modules as circles isntead of squares
$options->drawCircularModules = true;
$options->circleRadius = 0.4;
// connect paths
$options->connectPaths = true;
// keep modules of these types as square
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
$options->svgDefs = '
<linearGradient id="rainbow" x1="1" y2="1">
<stop stop-color="#e2453c" offset="0"/>
<stop stop-color="#e07e39" offset="0.2"/>
@@ -51,10 +50,18 @@ $options = new QROptions([
<style><![CDATA[
.dark{fill: url(#rainbow);}
.light{fill: #eee;}
]]></style>',
]);
]]></style>';
try{
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
}
catch(Throwable $e){
// handle the exception in whatever way you need
exit($e->getMessage());
}
$qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
if(php_sapi_name() !== 'cli'){
header('Content-type: image/svg+xml');
@@ -62,10 +69,10 @@ if(php_sapi_name() !== 'cli'){
if(extension_loaded('zlib')){
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
$qrcode = gzencode($qrcode, 9);
$out = gzencode($out, 9);
}
}
echo $qrcode;
echo $out;
exit;
+27 -25
View File
@@ -1,5 +1,7 @@
<?php
/**
* "melted" modules example
*
* This code generates an SVG QR code with rounded corners. It uses a round rect for each square and then additional
* paths to fill in the gap where squares are next to each other. Adjacent squares overlap - to almost completely
* eliminate hairline antialias "cracks" that tend to appear when two SVG paths are exactly adjacent to each other.
@@ -244,28 +246,28 @@ class MeltedOutputOptions extends QROptions{
/*
* Runtime
*/
$options = new MeltedOutputOptions;
$options = new MeltedOutputOptions([
'melt' => true,
'inverseMelt' => true,
'meltRadius' => 0.4,
// settings from the custom options class
$options->melt = true;
$options->inverseMelt = true;
$options->meltRadius = 0.4;
'version' => 7,
'eccLevel' => EccLevel::H,
'addQuietzone' => true,
'addLogoSpace' => true,
'logoSpaceWidth' => 13,
'logoSpaceHeight' => 13,
'connectPaths' => true,
'imageBase64' => false,
'outputType' => QROutputInterface::CUSTOM,
'outputInterface' => MeltedSVGQRCodeOutput::class,
'excludeFromConnect' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
],
'svgDefs' => '
$options->version = 7;
$options->outputType = QROutputInterface::CUSTOM;
$options->outputInterface = MeltedSVGQRCodeOutput::class;
$options->imageBase64 = false;
$options->addQuietzone = true;
$options->eccLevel = EccLevel::H;
$options->addLogoSpace = true;
$options->logoSpaceWidth = 13;
$options->logoSpaceHeight = 13;
$options->connectPaths = true;
$options->excludeFromConnect = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
];
$options->svgDefs = '
<linearGradient id="rainbow" x1="100%" y2="100%">
<stop stop-color="#e2453c" offset="2.5%"/>
<stop stop-color="#e07e39" offset="21.5%"/>
@@ -276,11 +278,11 @@ $options = new MeltedOutputOptions([
</linearGradient>
<style><![CDATA[
.light, .dark{fill: url(#rainbow);}
]]></style>',
]);
]]></style>';
$qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
if(php_sapi_name() !== 'cli'){
header('Content-type: image/svg+xml');
@@ -288,10 +290,10 @@ if(php_sapi_name() !== 'cli'){
if(extension_loaded('zlib')){
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
$qrcode = gzencode($qrcode, 9);
$out = gzencode($out, 9);
}
}
echo $qrcode;
echo $out;
exit;
+35 -29
View File
@@ -1,5 +1,7 @@
<?php
/**
* Randomly colored modules example
*
* @see https://github.com/chillerlan/php-qrcode/discussions/136
*
* @created 09.07.2022
@@ -98,8 +100,11 @@ class RandomDotsOptions extends QROptions{
* Runtime
*/
// prepare the options
$options = new RandomDotsOptions;
// our custom dot colors
$dotColors = [
$options->dotColors = [
111 => '#e2453c',
222 => '#e07e39',
333 => '#e5d667',
@@ -111,50 +116,51 @@ $dotColors = [
// generate the CSS for the several colored layers
$layerColors = '';
foreach($dotColors as $layer => $color){
foreach($options->dotColors as $layer => $color){
$layerColors .= sprintf("\n\t\t.qr-%s{ fill: %s; }", $layer, $color);
}
// prepare the options
$options = new RandomDotsOptions([
'dotColors' => $dotColors,
'svgDefs' => '
$options->svgDefs = '
<style><![CDATA[
.light{ fill: #dedede; }
.dark{ fill: #424242; }
'.$layerColors.'
]]></style>',
]]></style>';
'version' => 5,
'eccLevel' => EccLevel::H,
'addQuietzone' => true,
'imageBase64' => false,
'outputType' => QROutputInterface::CUSTOM,
'outputInterface' => RandomDotsSVGOutput::class,
'drawLightModules' => false,
// set the custom output interface
$options->outputType = QROutputInterface::CUSTOM;
$options->outputInterface = RandomDotsSVGOutput::class;
'connectPaths' => true,
'excludeFromConnect' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
],
// common qrcode options
$options->version = 5;
$options->eccLevel = EccLevel::H;
$options->addQuietzone = true;
$options->imageBase64 = false;
$options->drawLightModules = false;
$options->connectPaths = true;
$options->excludeFromConnect = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
$options->drawCircularModules = true;
$options->circleRadius = 0.4;
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
'drawCircularModules' => true,
'circleRadius' => 0.4,
'keepAsSquare' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
],
]);
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
// dump the output
if(php_sapi_name() !== 'cli'){
header('content-type: image/svg+xml');
}
echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
echo $out;
exit;
+40 -39
View File
@@ -1,5 +1,7 @@
<?php
/**
* round quiet zone example
*
* @see https://github.com/chillerlan/php-qrcode/discussions/137
*
* @created 09.07.2022
@@ -270,7 +272,11 @@ class RoundQuietzoneOptions extends QROptions{
* Runtime
*/
$dotColors = [
$options = new RoundQuietzoneOptions;
// custom dot options (see extended class)
$options->additionalModules = 5;
$options->dotColors = [
111 => '#e2453c',
222 => '#e07e39',
333 => '#e5d667',
@@ -279,15 +285,16 @@ $dotColors = [
666 => '#6f5ba7',
];
// generate the CSS for the several colored layers
$layerColors = '';
foreach($dotColors as $layer => $color){
foreach($options->dotColors as $layer => $color){
$layerColors .= sprintf("\n\t\t.qr-%s{ fill: %s; }", $layer, $color);
}
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
// please forgive me for I have committed colorful crimes
$svgDefs = '
$options->svgDefs = '
<linearGradient id="blurple" x1="100%" y2="100%">
<stop stop-color="#D70071" offset="0"/>
<stop stop-color="#9C4E97" offset="0.5"/>
@@ -309,44 +316,38 @@ $svgDefs = '
'.$layerColors.'
]]></style>';
$options = new RoundQuietzoneOptions([
// custom dot options
'additionalModules' => 5,
'dotColors' => $dotColors,
// custom SVG logo options
$options->svgLogo = __DIR__.'/github.svg'; // logo from: https://github.com/simple-icons/simple-icons
$options->svgLogoScale = 0.2;
$options->svgLogoCssClass = 'logo';
// custom SVG logo options (see extended class below)
'svgLogo' => __DIR__.'/github.svg', // logo from: https://github.com/simple-icons/simple-icons
'svgLogoScale' => 0.2,
'svgLogoCssClass' => 'logo',
// common QRCode options
$options->version = 7;
$options->eccLevel = EccLevel::H;
$options->addQuietzone = false; // we're not adding a quiet zone, this is done internally in our own module
$options->imageBase64 = false; // avoid base64 URI output for the example
$options->outputType = QROutputInterface::CUSTOM;
$options->outputInterface = RoundQuietzoneSVGoutput::class; // load our own output class
$options->drawLightModules = false; // set to true to add the light modules
// common SVG options
#$options->connectPaths = true; // this has been set to "always on" internally
$options->excludeFromConnect = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
QRMatrix::M_QUIETZONE_DARK,
];
$options->drawCircularModules = true;
$options->circleRadius = 0.4;
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
// common QRCode options
'version' => 7,
'eccLevel' => EccLevel::H, // maximum error correction capacity, esp. for print
'addQuietzone' => false, // we're not adding a quiet zone, this is done internally in our own module
'imageBase64' => false, // avoid base64 URI output
'outputType' => QROutputInterface::CUSTOM,
'outputInterface' => RoundQuietzoneSVGoutput::class, // load our own output class
'drawLightModules' => false, // set to true to add the light modules
// common SVG options
'svgDefs' => $svgDefs,
// 'connectPaths' => true, // this has been set to "always on" internally
'excludeFromConnect' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
QRMatrix::M_QUIETZONE_DARK,
],
'drawCircularModules' => true,
'circleRadius' => 0.4,
'keepAsSquare' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
],
]);
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
$qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
if(php_sapi_name() !== 'cli'){
header('Content-type: image/svg+xml');
@@ -354,10 +355,10 @@ if(php_sapi_name() !== 'cli'){
if(extension_loaded('zlib')){
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
$qrcode = gzencode($qrcode, 9);
$out = gzencode($out, 9);
}
}
echo $qrcode;
echo $out;
exit;
+31 -33
View File
@@ -1,5 +1,7 @@
<?php
/**
* SVG with logo example
*
* @created 05.03.2022
* @author smiley <smiley@chillerlan.net>
* @copyright 2022 smiley
@@ -103,34 +105,30 @@ class SVGWithLogoOptions extends QROptions{
* Runtime
*/
$options = new SVGWithLogoOptions([
// SVG logo options (see extended class below)
'svgLogo' => __DIR__.'/github.svg', // logo from: https://github.com/simple-icons/simple-icons
'svgLogoScale' => 0.25,
'svgLogoCssClass' => 'dark',
// QROptions
'version' => 5,
'outputType' => QROutputInterface::CUSTOM,
'outputInterface' => QRSvgWithLogo::class,
'imageBase64' => false,
// ECC level H is necessary when using logos
'eccLevel' => EccLevel::H,
'addQuietzone' => true,
// if set to true, the light modules won't be rendered
'drawLightModules' => true,
// draw the modules as circles isntead of squares
'drawCircularModules' => true,
'circleRadius' => 0.45,
// connect paths
'connectPaths' => true,
// keep modules of thhese types as square
'keepAsSquare' => [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
],
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
'svgDefs' => '
$options = new SVGWithLogoOptions;
// SVG logo options (see extended class)
$options->svgLogo = __DIR__.'/github.svg'; // logo from: https://github.com/simple-icons/simple-icons
$options->svgLogoScale = 0.25;
$options->svgLogoCssClass = 'dark';
// QROptions
$options->version = 5;
$options->outputType = QROutputInterface::CUSTOM;
$options->outputInterface = QRSvgWithLogo::class;
$options->imageBase64 = false;
$options->eccLevel = EccLevel::H; // ECC level H is necessary when using logos
$options->addQuietzone = true;
$options->drawLightModules = true;
$options->connectPaths = true;
$options->drawCircularModules = true;
$options->circleRadius = 0.45;
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
$options->svgDefs = '
<linearGradient id="gradient" x1="100%" y2="100%">
<stop stop-color="#D70071" offset="0"/>
<stop stop-color="#9C4E97" offset="0.5"/>
@@ -139,10 +137,10 @@ $options = new SVGWithLogoOptions([
<style><![CDATA[
.dark{fill: url(#gradient);}
.light{fill: #eaeaea;}
]]></style>',
]);
]]></style>';
$qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
if(php_sapi_name() !== 'cli'){
@@ -151,10 +149,10 @@ if(php_sapi_name() !== 'cli'){
if(extension_loaded('zlib')){
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
$qrcode = gzencode($qrcode, 9);
$out = gzencode($out, 9);
}
}
echo $qrcode;
echo $out;
exit;
+6 -3
View File
@@ -1,5 +1,7 @@
<?php
/**
* SVG with logo and custom shapes example
*
* @see https://github.com/chillerlan/php-qrcode/discussions/150
*
* @created 05.03.2022
@@ -185,7 +187,8 @@ $options->svgDefs = '
.light{fill: #eaeaea;}
]]></style>';
$qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
if(php_sapi_name() !== 'cli'){
@@ -194,10 +197,10 @@ if(php_sapi_name() !== 'cli'){
if(extension_loaded('zlib')){
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
$qrcode = gzencode($qrcode, 9);
$out = gzencode($out, 9);
}
}
echo $qrcode;
echo $out;
exit;
+46 -43
View File
@@ -9,54 +9,57 @@
*/
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Common\EccLevel;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\QROutputInterface;
use PHPUnit\Util\Color;
require_once __DIR__.'/../vendor/autoload.php';
$options = new QROptions([
'version' => 7,
'outputType' => QROutputInterface::STRING_TEXT,
'eccLevel' => EccLevel::L,
'eol' => Color::colorize('reset', "\x00\n"),
'moduleValues' => [
// finder
QRMatrix::M_FINDER_DARK => Color::colorize('fg-black', '🔴'), // dark (true)
QRMatrix::M_FINDER => Color::colorize('fg-black', '⭕'), // light (false)
QRMatrix::M_FINDER_DOT => Color::colorize('fg-black', '🔴'), // finder dot, dark (true)
// alignment
QRMatrix::M_ALIGNMENT_DARK => Color::colorize('fg-blue', '🔴'),
QRMatrix::M_ALIGNMENT => Color::colorize('fg-blue', '⭕'),
// timing
QRMatrix::M_TIMING_DARK => Color::colorize('fg-red', '🔴'),
QRMatrix::M_TIMING => Color::colorize('fg-red', '⭕'),
// format
QRMatrix::M_FORMAT_DARK => Color::colorize('fg-magenta', '🔴'),
QRMatrix::M_FORMAT => Color::colorize('fg-magenta', '⭕'),
// version
QRMatrix::M_VERSION_DARK => Color::colorize('fg-green', '🔴'),
QRMatrix::M_VERSION => Color::colorize('fg-green', '⭕'),
// data
QRMatrix::M_DATA_DARK => Color::colorize('fg-white', '🔴'),
QRMatrix::M_DATA => Color::colorize('fg-white', '⭕'),
// darkmodule
QRMatrix::M_DARKMODULE => Color::colorize('fg-black', '🔴'),
// separator
QRMatrix::M_SEPARATOR => Color::colorize('fg-cyan', '⭕'),
// quietzone
QRMatrix::M_QUIETZONE => Color::colorize('fg-cyan', '⭕'),
// logo space
QRMatrix::M_LOGO => Color::colorize('fg-yellow', '⭕'),
// empty
QRMatrix::M_NULL => Color::colorize('fg-black', '⭕'),
// data
QRMatrix::M_TEST_DARK => Color::colorize('fg-white', '🔴'),
QRMatrix::M_TEST => Color::colorize('fg-black', '⭕'),
],
]);
$options = new QROptions;
echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
$options->version = 3;
$options->quietzoneSize = 2;
$options->outputType = QROutputInterface::STRING_TEXT;
$options->eol = "\n";
$options->textLineStart = str_repeat(' ', 6);
$options->textDark = ansi8('██', 253);
$options->textLight = ansi8('░░', 253);
$options->moduleValues = [
// finder
QRMatrix::M_FINDER_DARK => ansi8('██', 124),
QRMatrix::M_FINDER => ansi8('░░', 124),
QRMatrix::M_FINDER_DOT => ansi8('██', 124),
// alignment
QRMatrix::M_ALIGNMENT_DARK => ansi8('██', 2),
QRMatrix::M_ALIGNMENT => ansi8('░░', 2),
// timing
QRMatrix::M_TIMING_DARK => ansi8('██', 184),
QRMatrix::M_TIMING => ansi8('░░', 184),
// format
QRMatrix::M_FORMAT_DARK => ansi8('██', 200),
QRMatrix::M_FORMAT => ansi8('░░', 200),
// version
QRMatrix::M_VERSION_DARK => ansi8('██', 21),
QRMatrix::M_VERSION => ansi8('░░', 21),
// dark module
QRMatrix::M_DARKMODULE => ansi8('██', 53),
// data
QRMatrix::M_DATA_DARK => ansi8('██', 166),
QRMatrix::M_DATA => ansi8('░░', 166),
];
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
echo "\n\n\n$out\n\n\n";
exit;
// a little helper to a create proper ANSI 8-bit color escape sequence
function ansi8(string $str, int $color, bool $background = false):string{
$color = max(0, min($color, 255));
$background = ($background ? 48 : 38);
return sprintf("\x1b[%s;5;%sm%s\x1b[0m", $background, $color, $str);
}