diff --git a/src/Renderer/Image/ImagickImageBackEnd.php b/src/Renderer/Image/ImagickImageBackEnd.php index f1a94e5..adec85e 100644 --- a/src/Renderer/Image/ImagickImageBackEnd.php +++ b/src/Renderer/Image/ImagickImageBackEnd.php @@ -227,10 +227,7 @@ private function drawPath(Path $path) : void private function createGradientFill(Gradient $gradient, float $x, float $y, float $width, float $height) : string { - list($width, $height) = $this->matrices[$this->matrixIndex]->apply($x + $width, $y + $height); - list($x, $y) = $this->matrices[$this->matrixIndex]->apply($x, $y); - $width -= $x; - $height -= $y; + list($width, $height) = $this->matrices[$this->matrixIndex]->apply($width, $height); $startColor = $this->getColorPixel($gradient->getStartColor())->getColorAsString(); $endColor = $this->getColorPixel($gradient->getEndColor())->getColorAsString(); @@ -290,8 +287,8 @@ private function createGradientFill(Gradient $gradient, float $x, float $y, floa } $id = sprintf('g%d', ++$this->gradientCount); - $this->draw->pushPattern($id, 0, 0, $x + $width, $y + $height); - $this->draw->composite(Imagick::COMPOSITE_COPY, $x, $y, $width, $height, $gradientImage); + $this->draw->pushPattern($id, 0, 0, $width, $height); + $this->draw->composite(Imagick::COMPOSITE_COPY, 0, 0, $width, $height, $gradientImage); $this->draw->popPattern(); return $id; } diff --git a/test/Integration/ImagickRenderingTest.php b/test/Integration/ImagickRenderingTest.php index 6c86adc..39e44bf 100644 --- a/test/Integration/ImagickRenderingTest.php +++ b/test/Integration/ImagickRenderingTest.php @@ -3,8 +3,15 @@ namespace BaconQrCodeTest\Integration; +use BaconQrCode\Renderer\Color\Rgb; +use BaconQrCode\Renderer\Eye\SquareEye; use BaconQrCode\Renderer\Image\ImagickImageBackEnd; use BaconQrCode\Renderer\ImageRenderer; +use BaconQrCode\Renderer\Module\SquareModule; +use BaconQrCode\Renderer\RendererStyle\EyeFill; +use BaconQrCode\Renderer\RendererStyle\Fill; +use BaconQrCode\Renderer\RendererStyle\Gradient; +use BaconQrCode\Renderer\RendererStyle\GradientType; use BaconQrCode\Renderer\RendererStyle\RendererStyle; use BaconQrCode\Writer; use PHPUnit\Framework\TestCase; @@ -27,4 +34,30 @@ public function testGenericQrCode() : void $this->assertMatchesFileSnapshot($tempName); unlink($tempName); } + + public function testIssue79() : void + { + $eye = SquareEye::instance(); + $squareModule = SquareModule::instance(); + + $eyeFill = new EyeFill(new Rgb(100, 100, 55), new Rgb(100, 100, 255)); + $gradient = new Gradient(new Rgb(100, 100, 55), new Rgb(100, 100, 255), GradientType::HORIZONTAL()); + + $renderer = new ImageRenderer( + new RendererStyle( + 400, + 2, + $squareModule, + $eye, + Fill::withForegroundGradient(new Rgb(255, 255, 255), $gradient, $eyeFill, $eyeFill, $eyeFill) + ), + new ImagickImageBackEnd() + ); + $writer = new Writer($renderer); + $tempName = tempnam(sys_get_temp_dir(), 'test') . '.png'; + $writer->writeFile('https://apiroad.net/very-long-url', $tempName); + + $this->assertMatchesFileSnapshot($tempName); + unlink($tempName); + } } diff --git a/test/Integration/__snapshots__/files/ImagickRenderingTest__testIssue79__1.png b/test/Integration/__snapshots__/files/ImagickRenderingTest__testIssue79__1.png new file mode 100644 index 0000000..47e3b1a Binary files /dev/null and b/test/Integration/__snapshots__/files/ImagickRenderingTest__testIssue79__1.png differ