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'); - -?> + diff --git a/examples/image.php b/examples/image.php index 3da0b887f..165386642 100644 --- a/examples/image.php +++ b/examples/image.php @@ -1,5 +1,7 @@ * @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'); diff --git a/examples/imageWithLogo.php b/examples/imageWithLogo.php index 67428ff86..522fa4b53 100644 --- a/examples/imageWithLogo.php +++ b/examples/imageWithLogo.php @@ -1,5 +1,7 @@ * @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; diff --git a/examples/imageWithText.php b/examples/imageWithText.php index f586b6a9e..8de9dc880 100644 --- a/examples/imageWithText.php +++ b/examples/imageWithText.php @@ -1,6 +1,7 @@ 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; diff --git a/examples/imagick.php b/examples/imagick.php index 4f494f841..7235d72aa 100644 --- a/examples/imagick.php +++ b/examples/imagick.php @@ -1,5 +1,7 @@ * @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; diff --git a/examples/imagickWithLogo.php b/examples/imagickWithLogo.php index 4f120ea16..358b6b502 100644 --- a/examples/imagickWithLogo.php +++ b/examples/imagickWithLogo.php @@ -1,5 +1,7 @@ * @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; diff --git a/examples/multimode.php b/examples/multimode.php index 1a98b18f3..d8a4e5bb6 100644 --- a/examples/multimode.php +++ b/examples/multimode.php @@ -1,6 +1,6 @@ @@ -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; diff --git a/examples/reflectance.php b/examples/reflectance.php index 2bf36a4e3..5887deb45 100644 --- a/examples/reflectance.php +++ b/examples/reflectance.php @@ -1,6 +1,6 @@ @@ -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');
renderMatrix($matrix); - echo $qrcode->renderMatrix($matrix->invert()); + echo $out_normal; + echo $out_inverted; ?>
- * @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 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 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 = ' @@ -51,10 +50,18 @@ $options = new QROptions([ ', -]); + ]]>'; + + +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; diff --git a/examples/svgMeltedModules.php b/examples/svgMeltedModules.php index 86ed2bbc8..94952dc57 100644 --- a/examples/svgMeltedModules.php +++ b/examples/svgMeltedModules.php @@ -1,5 +1,7 @@ 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 = ' @@ -276,11 +278,11 @@ $options = new MeltedOutputOptions([ ', -]); + ]]>'; -$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; diff --git a/examples/svgRandomColoredDots.php b/examples/svgRandomColoredDots.php index 7faf64089..9a3e6e063 100644 --- a/examples/svgRandomColoredDots.php +++ b/examples/svgRandomColoredDots.php @@ -1,5 +1,7 @@ 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 = ' ', + ]]>'; - '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; diff --git a/examples/svgRoundQuietzone.php b/examples/svgRoundQuietzone.php index fd8749c0a..bd3773a58 100644 --- a/examples/svgRoundQuietzone.php +++ b/examples/svgRoundQuietzone.php @@ -1,5 +1,7 @@ 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 = ' @@ -309,44 +316,38 @@ $svgDefs = ' '.$layerColors.' ]]>'; -$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; diff --git a/examples/svgWithLogo.php b/examples/svgWithLogo.php index 271acb4e2..096b75948 100644 --- a/examples/svgWithLogo.php +++ b/examples/svgWithLogo.php @@ -1,5 +1,7 @@ * @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 = ' @@ -139,10 +137,10 @@ $options = new SVGWithLogoOptions([ ', -]); + ]]>'; -$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; diff --git a/examples/svgWithLogoAndCustomShapes.php b/examples/svgWithLogoAndCustomShapes.php index 04f021e1a..f8a1c9ac2 100644 --- a/examples/svgWithLogoAndCustomShapes.php +++ b/examples/svgWithLogoAndCustomShapes.php @@ -1,5 +1,7 @@ svgDefs = ' .light{fill: #eaeaea;} ]]>'; -$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; diff --git a/examples/text.php b/examples/text.php index 453bbee4e..7154b448f 100644 --- a/examples/text.php +++ b/examples/text.php @@ -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); +}