diff --git a/examples/MyCustomOutput.php b/examples/MyCustomOutput.php deleted file mode 100644 index 75835b0e9..000000000 --- a/examples/MyCustomOutput.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @copyright 2017 Smiley - * @license MIT - */ - -use chillerlan\QRCode\Output\QROutputAbstract; - -class MyCustomOutput extends QROutputAbstract{ - - protected function setModuleValues():void{ - // TODO: Implement setModuleValues() method. - } - - public function dump(string $file = null){ - - $output = ''; - - for($row = 0; $row < $this->moduleCount; $row++){ - for($col = 0; $col < $this->moduleCount; $col++){ - $output .= (int)$this->matrix->check($col, $row); - } - - $output .= \PHP_EOL; - } - - return $output; - } - -} diff --git a/examples/QRImageWithLogo.php b/examples/QRImageWithLogo.php deleted file mode 100644 index fd84800ac..000000000 --- a/examples/QRImageWithLogo.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @copyright 2020 smiley - * @license MIT - * - * @noinspection PhpComposerExtensionStubsInspection - */ - -use chillerlan\QRCode\Output\{QRCodeOutputException, QRImage}; - -use function imagecopyresampled, imagecreatefrompng, imagesx, imagesy, is_file, is_readable; - -class QRImageWithLogo extends QRImage{ - - /** - * @param string|null $file - * @param string|null $logo - * - * @return string - * @throws \chillerlan\QRCode\Output\QRCodeOutputException - */ - public function dump(string $file = null, string $logo = null):string{ - // set returnResource to true to skip further processing for now - $this->options->returnResource = true; - - // of course you could accept other formats too (such as resource or Imagick) - // i'm not checking for the file type either for simplicity reasons (assuming PNG) - if(!is_file($logo) || !is_readable($logo)){ - throw new QRCodeOutputException('invalid logo'); - } - - $this->matrix->setLogoSpace( - $this->options->logoSpaceWidth, - $this->options->logoSpaceHeight - // not utilizing the position here - ); - - // there's no need to save the result of dump() into $this->image here - parent::dump($file); - - $im = imagecreatefrompng($logo); - - // get logo image size - $w = imagesx($im); - $h = imagesy($im); - - // set new logo size, leave a border of 1 module (no proportional resize/centering) - $lw = ($this->options->logoSpaceWidth - 2) * $this->options->scale; - $lh = ($this->options->logoSpaceHeight - 2) * $this->options->scale; - - // get the qrcode size - $ql = $this->matrix->size() * $this->options->scale; - - // scale the logo and copy it over. done! - imagecopyresampled($this->image, $im, ($ql - $lw) / 2, ($ql - $lh) / 2, 0, 0, $lw, $lh, $w, $h); - - $imageData = $this->dumpImage(); - - if($file !== null){ - $this->saveToFile($imageData, $file); - } - - if($this->options->imageBase64){ - $imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData); - } - - return $imageData; - } - -} diff --git a/examples/QRImageWithText.php b/examples/QRImageWithText.php deleted file mode 100644 index 120fbf01a..000000000 --- a/examples/QRImageWithText.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @copyright 2019 smiley - * @license MIT - * - * @noinspection PhpComposerExtensionStubsInspection - */ - -use chillerlan\QRCode\Output\QRImage; - -use function base64_encode, imagechar, imagecolorallocate, imagecolortransparent, imagecopymerge, imagecreatetruecolor, - imagedestroy, imagefilledrectangle, imagefontwidth, in_array, round, str_split, strlen; - -class QRImageWithText extends QRImage{ - - /** - * @param string|null $file - * @param string|null $text - * - * @return string - */ - public function dump(string $file = null, string $text = null):string{ - // set returnResource to true to skip further processing for now - $this->options->returnResource = true; - - // there's no need to save the result of dump() into $this->image here - parent::dump($file); - - // render text output if a string is given - if($text !== null){ - $this->addText($text); - } - - $imageData = $this->dumpImage(); - - if($file !== null){ - $this->saveToFile($imageData, $file); - } - - if($this->options->imageBase64){ - $imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData); - } - - return $imageData; - } - - /** - * @param string $text - */ - protected function addText(string $text):void{ - // save the qrcode image - $qrcode = $this->image; - - // options things - $textSize = 3; // see imagefontheight() and imagefontwidth() - $textBG = [200, 200, 200]; - $textColor = [50, 50, 50]; - - $bgWidth = $this->length; - $bgHeight = $bgWidth + 20; // 20px extra space - - // create a new image with additional space - $this->image = imagecreatetruecolor($bgWidth, $bgHeight); - $background = imagecolorallocate($this->image, ...$textBG); - - // allow transparency - if($this->options->imageTransparent && in_array($this->options->outputType, $this::TRANSPARENCY_TYPES, true)){ - imagecolortransparent($this->image, $background); - } - - // fill the background - imagefilledrectangle($this->image, 0, 0, $bgWidth, $bgHeight, $background); - - // copy over the qrcode - imagecopymerge($this->image, $qrcode, 0, 0, 0, 0, $this->length, $this->length, 100); - imagedestroy($qrcode); - - $fontColor = imagecolorallocate($this->image, ...$textColor); - $w = imagefontwidth($textSize); - $x = round(($bgWidth - strlen($text) * $w) / 2); - - // loop through the string and draw the letters - foreach(str_split($text) as $i => $chr){ - imagechar($this->image, $textSize, (int)($i * $w + $x), $this->length, $chr, $fontColor); - } - } - -} diff --git a/examples/custom_output.php b/examples/custom_output.php index 86f45c99b..e00f2146c 100644 --- a/examples/custom_output.php +++ b/examples/custom_output.php @@ -9,10 +9,33 @@ */ use chillerlan\QRCode\{QRCode, QROptions}; +use chillerlan\QRCode\Output\QROutputAbstract; require_once __DIR__.'/../vendor/autoload.php'; -$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; +class MyCustomOutput extends QROutputAbstract{ + + protected function setModuleValues():void{ + // TODO: Implement setModuleValues() method. + } + + public function dump(string $file = null){ + + $output = ''; + + for($row = 0; $row < $this->moduleCount; $row++){ + for($col = 0; $col < $this->moduleCount; $col++){ + $output .= (int)$this->matrix->check($col, $row); + } + + $output .= PHP_EOL; + } + + return $output; + } + +} + // invoke the QROutputInterface manually $options = new QROptions([ @@ -20,9 +43,9 @@ $options = new QROptions([ 'eccLevel' => QRCode::ECC_L, ]); -$qrOutputInterface = new MyCustomOutput($options, (new QRCode($options))->getMatrix($data)); +$qrOutputInterface = new MyCustomOutput($options, (new QRCode($options))->getMatrix('https://www.youtube.com/watch?v=dQw4w9WgXcQ')); -var_dump($qrOutputInterface->dump()); +echo '
'.$qrOutputInterface->dump().''; // or just @@ -33,4 +56,4 @@ $options = new QROptions([ 'outputInterface' => MyCustomOutput::class, ]); -var_dump((new QRCode($options))->render($data)); +echo '
'.(new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ').'';
diff --git a/examples/fpdf.php b/examples/fpdf.php
index 0b42c3e6c..aab286e2d 100644
--- a/examples/fpdf.php
+++ b/examples/fpdf.php
@@ -1,45 +1,51 @@
7,
- 'outputType' => QRCode::OUTPUT_FPDF,
- 'eccLevel' => QRCode::ECC_L,
- 'scale' => 5,
- 'imageBase64' => false,
- 'moduleValues' => [
- // finder
- 1536 => [0, 63, 255], // dark (true)
- 6 => [255, 255, 255], // light (false), white is the transparency color and is enabled by default
- // alignment
- 2560 => [255, 0, 255],
- 10 => [255, 255, 255],
- // timing
- 3072 => [255, 0, 0],
- 12 => [255, 255, 255],
- // format
- 3584 => [67, 191, 84],
- 14 => [255, 255, 255],
- // version
- 4096 => [62, 174, 190],
- 16 => [255, 255, 255],
- // data
- 1024 => [0, 0, 0],
- 4 => [255, 255, 255],
- // darkmodule
- 512 => [0, 0, 0],
- // separator
- 8 => [255, 255, 255],
- // quietzone
- 18 => [255, 255, 255],
- ],
+ 'version' => 7,
+ 'outputType' => QRCode::OUTPUT_FPDF,
+ 'eccLevel' => QRCode::ECC_L,
+ 'scale' => 5,
+ 'imageBase64' => false,
+ 'moduleValues' => [
+ // finder
+ (QRMatrix::M_FINDER << 8) => [0, 63, 255], // dark (true)
+ (QRMatrix::M_FINDER_DOT << 8) => [0, 63, 255],
+ QRMatrix::M_FINDER => [255, 255, 255], // light (false), white is the transparency color and is enabled by default
+ // alignment
+ (QRMatrix::M_ALIGNMENT << 8) => [255, 0, 255],
+ QRMatrix::M_ALIGNMENT => [255, 255, 255],
+ // timing
+ (QRMatrix::M_TIMING << 8) => [255, 0, 0],
+ QRMatrix::M_TIMING => [255, 255, 255],
+ // format
+ (QRMatrix::M_FORMAT << 8) => [67, 191, 84],
+ QRMatrix::M_FORMAT => [255, 255, 255],
+ // version
+ (QRMatrix::M_VERSION << 8) => [62, 174, 190],
+ QRMatrix::M_VERSION => [255, 255, 255],
+ // data
+ (QRMatrix::M_DATA << 8) => [0, 0, 0],
+ QRMatrix::M_DATA => [255, 255, 255],
+ // darkmodule
+ (QRMatrix::M_DARKMODULE << 8) => [0, 0, 0],
+ // separator
+ QRMatrix::M_SEPARATOR => [255, 255, 255],
+ // quietzone
+ QRMatrix::M_QUIETZONE => [255, 255, 255],
+ ],
]);
-\header('Content-type: application/pdf');
-echo (new QRCode($options))->render($data);
+header('Content-type: application/pdf');
+
+echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
diff --git a/examples/html.php b/examples/html.php
index 16258552b..935210efa 100644
--- a/examples/html.php
+++ b/examples/html.php
@@ -1,7 +1,5 @@
* @copyright 2017 Smiley
@@ -9,9 +7,45 @@
*/
use chillerlan\QRCode\{QRCode, QROptions};
+use chillerlan\QRCode\Data\QRMatrix;
require_once '../vendor/autoload.php';
+$options = new QROptions([
+ 'version' => 5,
+ 'outputType' => QRCode::OUTPUT_MARKUP_HTML,
+ 'cssClass' => 'qrcode',
+ 'eccLevel' => QRCode::ECC_L,
+ 'moduleValues' => [
+ // finder
+ (QRMatrix::M_FINDER << 8) => '#A71111', // dark (true)
+ (QRMatrix::M_FINDER_DOT << 8) => '#A71111',
+ QRMatrix::M_FINDER => '#FFBFBF', // light (false)
+ // alignment
+ (QRMatrix::M_ALIGNMENT << 8) => '#A70364',
+ QRMatrix::M_ALIGNMENT => '#FFC9C9',
+ // timing
+ (QRMatrix::M_TIMING << 8) => '#98005D',
+ QRMatrix::M_TIMING => '#FFB8E9',
+ // format
+ (QRMatrix::M_FORMAT << 8) => '#003804',
+ QRMatrix::M_FORMAT => '#00FB12',
+ // version
+ (QRMatrix::M_VERSION << 8) => '#650098',
+ QRMatrix::M_VERSION => '#E0B8FF',
+ // data
+ (QRMatrix::M_DATA << 8) => '#4A6000',
+ QRMatrix::M_DATA => '#ECF9BE',
+ // darkmodule
+ (QRMatrix::M_DARKMODULE << 8) => '#080063',
+ // separator
+ QRMatrix::M_SEPARATOR => '#AFBFBF',
+ // quietzone
+ QRMatrix::M_QUIETZONE => '#FFFFFF',
+ ],
+]);
+
+
header('Content-Type: text/html; charset=utf-8');
?>
@@ -23,7 +57,7 @@ header('Content-Type: text/html; charset=utf-8');