diff --git a/examples/authenticator.php b/examples/authenticator.php
index e9ee7ed50..ec83dda09 100644
--- a/examples/authenticator.php
+++ b/examples/authenticator.php
@@ -1,6 +1,6 @@
@@ -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 = '
- ',
-];
+ ';
-// 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);
diff --git a/examples/custom_output.php b/examples/custom_output.php
index 5be1aea77..48f20aa37 100644
--- a/examples/custom_output.php
+++ b/examples/custom_output.php
@@ -1,5 +1,7 @@
* @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));
diff --git a/examples/eps.php b/examples/eps.php
index a2d2a0508..3a29dc2fb 100644
--- a/examples/eps.php
+++ b/examples/eps.php
@@ -1,5 +1,7 @@
* @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;
diff --git a/examples/fpdf.php b/examples/fpdf.php
index 975228ca5..fa231718d 100644
--- a/examples/fpdf.php
+++ b/examples/fpdf.php
@@ -1,58 +1,62 @@
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;
diff --git a/examples/html.php b/examples/html.php
index 2fcb21bba..283bf1fb0 100644
--- a/examples/html.php
+++ b/examples/html.php
@@ -1,5 +1,7 @@
* @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');
?>
@@ -55,7 +42,7 @@ header('Content-Type: text/html; charset=utf-8');
- QRCode test
+ QRCode HTML Example
-render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
-
-?>
+