Skip to content

Commit 709a032

Browse files
committed
:octocat: circular modules in Imagick output
1 parent dd9959b commit 709a032

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

examples/imagick.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
1818

1919
$options = new QROptions([
20-
'version' => 7,
21-
'outputType' => QRCode::OUTPUT_IMAGICK,
22-
'eccLevel' => EccLevel::L,
23-
'scale' => 5,
24-
'moduleValues' => [
20+
'version' => 7,
21+
'outputType' => QRCode::OUTPUT_IMAGICK,
22+
'eccLevel' => EccLevel::L,
23+
'scale' => 20,
24+
'drawCircularModules' => true,
25+
'circleRadius' => 0.4,
26+
'keepAsSquare' => [QRMatrix::M_FINDER|QRMatrix::IS_DARK, QRMatrix::M_FINDER_DOT, QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK],
27+
'moduleValues' => [
2528
// finder
2629
QRMatrix::M_FINDER | QRMatrix::IS_DARK => '#A71111', // dark (true)
2730
QRMatrix::M_FINDER => '#FFBFBF', // light (false)

src/Output/QRImagick.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function drawImage():void{
103103

104104
foreach($this->matrix->matrix() as $y => $row){
105105
foreach($row as $x => $M_TYPE){
106-
$this->drawPixel($x, $y, $M_TYPE);
106+
$this->setPixel($x, $y, $M_TYPE);
107107
}
108108
}
109109

@@ -113,14 +113,22 @@ protected function drawImage():void{
113113
/**
114114
* draws a single pixel at the given position
115115
*/
116-
protected function drawPixel(int $x, int $y, int $M_TYPE):void{
116+
protected function setPixel(int $x, int $y, int $M_TYPE):void{
117117
$this->imagickDraw->setStrokeColor($this->moduleValues[$M_TYPE]);
118118
$this->imagickDraw->setFillColor($this->moduleValues[$M_TYPE]);
119-
$this->imagickDraw->rectangle(
120-
$x * $this->scale,
121-
$y * $this->scale,
122-
($x + 1) * $this->scale,
123-
($y + 1) * $this->scale
119+
120+
$this->options->drawCircularModules && !$this->matrix->checkTypes($x, $y, $this->options->keepAsSquare)
121+
? $this->imagickDraw->circle(
122+
($x + 0.5) * $this->scale,
123+
($y + 0.5) * $this->scale,
124+
($x + 0.5 + $this->options->circleRadius) * $this->scale,
125+
($y + 0.5) * $this->scale
126+
)
127+
: $this->imagickDraw->rectangle(
128+
$x * $this->scale,
129+
$y * $this->scale,
130+
($x + 1) * $this->scale,
131+
($y + 1) * $this->scale
124132
);
125133
}
126134

0 commit comments

Comments
 (0)