From 8c439700427a42193e065de5fddf9d7935b8c73b Mon Sep 17 00:00:00 2001 From: bilogic <946010+bilogic@users.noreply.github.com> Date: Sun, 24 Dec 2023 21:43:59 +0800 Subject: [PATCH] refactor matrix into an overridable method (#434) * refactor matrix into an overridable method * fixed to return value --- src/Writer/AbstractGdWriter.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Writer/AbstractGdWriter.php b/src/Writer/AbstractGdWriter.php index a0080ef..428fafa 100644 --- a/src/Writer/AbstractGdWriter.php +++ b/src/Writer/AbstractGdWriter.php @@ -19,14 +19,23 @@ abstract class AbstractGdWriter implements WriterInterface, ValidatingWriterInterface { + /** + * Get the matrix. Can be overridden to perform custom punch outs. + */ + protected function getMatrix(QrCodeInterface $qrCode) + { + $matrixFactory = new MatrixFactory(); + + return $matrixFactory->create($qrCode); + } + public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface { if (!extension_loaded('gd')) { throw new \Exception('Unable to generate image: please check if the GD extension is enabled and configured correctly'); } - $matrixFactory = new MatrixFactory(); - $matrix = $matrixFactory->create($qrCode); + $matrix = $this->getMatrix($qrCode); $baseBlockSize = RoundBlockSizeMode::None === $qrCode->getRoundBlockSizeMode() ? 10 : intval($matrix->getBlockSize()); $baseImage = imagecreatetruecolor($matrix->getBlockCount() * $baseBlockSize, $matrix->getBlockCount() * $baseBlockSize);