:octocat: circular modules in Imagick output

This commit is contained in:
codemasher
2021-12-10 00:50:48 +01:00
parent dd9959b4c2
commit 709a0322c9
2 changed files with 23 additions and 12 deletions
+8 -5
View File
@@ -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)
+15 -7
View File
@@ -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
);
}