Skip to content

Commit

Permalink
refactor matrix into an overridable method (endroid#434)
Browse files Browse the repository at this point in the history
* refactor matrix into an overridable method

* fixed to return value
  • Loading branch information
bilogic authored Dec 24, 2023
1 parent c4c864a commit 8c43970
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Writer/AbstractGdWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8c43970

Please sign in to comment.