diff --git a/src/Writer/GdTrait.php b/src/Writer/GdTrait.php index a3069d64..e9cd4a3a 100644 --- a/src/Writer/GdTrait.php +++ b/src/Writer/GdTrait.php @@ -68,12 +68,11 @@ public function writeGd(QrCodeInterface $qrCode, ?LogoInterface $logo = null, ?L for ($rowIndex = 0; $rowIndex < $matrix->getBlockCount(); ++$rowIndex) { for ($columnIndex = 0; $columnIndex < $matrix->getBlockCount(); ++$columnIndex) { if (1 === $matrix->getBlockValue($rowIndex, $columnIndex)) { - imagefilledrectangle( + $this->addBlock( $baseImage, - $columnIndex * $baseBlockSize, - $rowIndex * $baseBlockSize, - ($columnIndex + 1) * $baseBlockSize - 1, - ($rowIndex + 1) * $baseBlockSize - 1, + $rowIndex, + $columnIndex, + $baseBlockSize, $foregroundColor ); } @@ -230,4 +229,25 @@ public function validateResult(ResultInterface $result, string $expectedData): v throw ValidationException::createForInvalidData($expectedData, strval($reader->text())); } } + + /** + * Draws a single square (block) to the image. + * Can be overwritten to use custom shapes instead of squares. + */ + public function addBlock( + \GdImage $baseImage, + int $rowIndex, + int $columnIndex, + int $baseBlockSize, + int $foregroundColor + ): void { + imagefilledrectangle( + $baseImage, + $columnIndex * $baseBlockSize, + $rowIndex * $baseBlockSize, + ($columnIndex + 1) * $baseBlockSize - 1, + ($rowIndex + 1) * $baseBlockSize - 1, + $foregroundColor + ); + } } diff --git a/src/Writer/PngWriter.php b/src/Writer/PngWriter.php index 1f6a51bc..7b465f2b 100644 --- a/src/Writer/PngWriter.php +++ b/src/Writer/PngWriter.php @@ -10,7 +10,7 @@ use Endroid\QrCode\Writer\Result\PngResult; use Endroid\QrCode\Writer\Result\ResultInterface; -final readonly class PngWriter implements WriterInterface, ValidatingWriterInterface +readonly class PngWriter implements WriterInterface, ValidatingWriterInterface { use GdTrait;