From 709a0322c91000c8ca4a332385c1c7ef4d8b3d72 Mon Sep 17 00:00:00 2001 From: codemasher Date: Fri, 10 Dec 2021 00:50:48 +0100 Subject: [PATCH] :octocat: circular modules in Imagick output --- examples/imagick.php | 13 ++++++++----- src/Output/QRImagick.php | 22 +++++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/examples/imagick.php b/examples/imagick.php index ea8af1d57..e64a5d80c 100644 --- a/examples/imagick.php +++ b/examples/imagick.php @@ -17,11 +17,14 @@ require_once __DIR__.'/../vendor/autoload.php'; $data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s'; $options = new QROptions([ - 'version' => 7, - 'outputType' => QRCode::OUTPUT_IMAGICK, - 'eccLevel' => EccLevel::L, - 'scale' => 5, - 'moduleValues' => [ + 'version' => 7, + 'outputType' => QRCode::OUTPUT_IMAGICK, + 'eccLevel' => EccLevel::L, + 'scale' => 20, + 'drawCircularModules' => true, + 'circleRadius' => 0.4, + 'keepAsSquare' => [QRMatrix::M_FINDER|QRMatrix::IS_DARK, QRMatrix::M_FINDER_DOT, QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK], + 'moduleValues' => [ // finder QRMatrix::M_FINDER | QRMatrix::IS_DARK => '#A71111', // dark (true) QRMatrix::M_FINDER => '#FFBFBF', // light (false) diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index 4fb15cb39..1ebed18d4 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -103,7 +103,7 @@ class QRImagick extends QROutputAbstract{ foreach($this->matrix->matrix() as $y => $row){ foreach($row as $x => $M_TYPE){ - $this->drawPixel($x, $y, $M_TYPE); + $this->setPixel($x, $y, $M_TYPE); } } @@ -113,14 +113,22 @@ class QRImagick extends QROutputAbstract{ /** * draws a single pixel at the given position */ - protected function drawPixel(int $x, int $y, int $M_TYPE):void{ + protected function setPixel(int $x, int $y, int $M_TYPE):void{ $this->imagickDraw->setStrokeColor($this->moduleValues[$M_TYPE]); $this->imagickDraw->setFillColor($this->moduleValues[$M_TYPE]); - $this->imagickDraw->rectangle( - $x * $this->scale, - $y * $this->scale, - ($x + 1) * $this->scale, - ($y + 1) * $this->scale + + $this->options->drawCircularModules && !$this->matrix->checkTypes($x, $y, $this->options->keepAsSquare) + ? $this->imagickDraw->circle( + ($x + 0.5) * $this->scale, + ($y + 0.5) * $this->scale, + ($x + 0.5 + $this->options->circleRadius) * $this->scale, + ($y + 0.5) * $this->scale + ) + : $this->imagickDraw->rectangle( + $x * $this->scale, + $y * $this->scale, + ($x + 1) * $this->scale, + ($y + 1) * $this->scale ); }