Skip to content

Commit

Permalink
Fix interpolation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed May 6, 2018
1 parent b62d333 commit 04a94d6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Writer/PngWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,26 @@ public function writeString(QrCodeInterface $qrCode): string
{
$data = $this->getData($qrCode);

$image = imagecreatetruecolor($data['outer_width'], $data['outer_height']);
$foregroundColor = imagecolorallocatealpha($image, $qrCode->getForegroundColor()['r'], $qrCode->getForegroundColor()['g'], $qrCode->getForegroundColor()['b'], $qrCode->getForegroundColor()['a']);
$backgroundColor = imagecolorallocatealpha($image, $qrCode->getBackgroundColor()['r'], $qrCode->getBackgroundColor()['g'], $qrCode->getBackgroundColor()['b'], $qrCode->getBackgroundColor()['a']);
imagefill($image, 0, 0, $backgroundColor);
$baseSize = $qrCode->getRoundBlockSize() ? $data['block_size'] : 25;
$baseImage = imagecreatetruecolor($data['block_count'] * $baseSize, $data['block_count'] * $baseSize);
$foregroundColor = imagecolorallocatealpha($baseImage, $qrCode->getForegroundColor()['r'], $qrCode->getForegroundColor()['g'], $qrCode->getForegroundColor()['b'], $qrCode->getForegroundColor()['a']);
$backgroundColor = imagecolorallocatealpha($baseImage, $qrCode->getBackgroundColor()['r'], $qrCode->getBackgroundColor()['g'], $qrCode->getBackgroundColor()['b'], $qrCode->getBackgroundColor()['a']);
imagefill($baseImage, 0, 0, $backgroundColor);

foreach ($data['matrix'] as $row => $values) {
foreach ($values as $column => $value) {
if (1 === $value) {
$x = $data['margin_left'] + $data['block_size'] * $column;
$y = $data['margin_left'] + $data['block_size'] * $row;
imagefilledrectangle($image, $x, $y, $x + $data['block_size'], $y + $data['block_size'], $foregroundColor);
imagefilledrectangle($baseImage, $column * $baseSize, $row * $baseSize, ($column + 1) * $baseSize, ($row + 1) * $baseSize, $foregroundColor);
}
}
}

$image = imagecreatetruecolor($data['outer_width'], $data['outer_height']);
$backgroundColor = imagecolorallocatealpha($image, $qrCode->getBackgroundColor()['r'], $qrCode->getBackgroundColor()['g'], $qrCode->getBackgroundColor()['b'], $qrCode->getBackgroundColor()['a']);
imagefill($image, 0, 0, $backgroundColor);

imagecopyresampled($image, $baseImage, $data['margin_left'], $data['margin_left'], 0, 0, $data['inner_width'], $data['inner_height'], $baseSize * $data['block_count'], $baseSize * $data['block_count']);

if ($qrCode->getLogoPath()) {
$image = $this->addLogo($image, $qrCode->getLogoPath(), $qrCode->getLogoWidth());
}
Expand Down

0 comments on commit 04a94d6

Please sign in to comment.