From 1151c3271a6fe212fc2cd3ac8248387ab51ad9a0 Mon Sep 17 00:00:00 2001 From: Alex Roth <115640054+psion-ar@users.noreply.github.com> Date: Thu, 18 Jul 2024 13:57:39 +0200 Subject: [PATCH] Fix bug in ImagickDriver::pixelate, Update tests (#267) --- src/Drivers/Imagick/ImagickDriver.php | 4 ++++ tests/Manipulations/BlurTest.php | 6 +++--- tests/Manipulations/PixelateTest.php | 11 ++++++++--- tests/Manipulations/SharpenTest.php | 6 +++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/Drivers/Imagick/ImagickDriver.php b/src/Drivers/Imagick/ImagickDriver.php index 75409036..003397df 100644 --- a/src/Drivers/Imagick/ImagickDriver.php +++ b/src/Drivers/Imagick/ImagickDriver.php @@ -470,6 +470,10 @@ public function flip(FlipDirection $flip): static public function pixelate(int $pixelate = 50): static { + if ($pixelate === 0) { + return $this; + } + $width = $this->getWidth(); $height = $this->getHeight(); diff --git a/tests/Manipulations/BlurTest.php b/tests/Manipulations/BlurTest.php index ed8939e5..8b16e25c 100644 --- a/tests/Manipulations/BlurTest.php +++ b/tests/Manipulations/BlurTest.php @@ -5,13 +5,13 @@ use function Spatie\Snapshots\assertMatchesImageSnapshot; -it('can blur an image', function (ImageDriver $driver) { +it('can blur an image', function (ImageDriver $driver, int $blur) { $targetFile = $this->tempDir->path("{$driver->driverName()}/blur.png"); - $driver->loadFile(getTestJpg())->blur(50)->save($targetFile); + $driver->loadFile(getTestJpg())->blur($blur)->save($targetFile); assertMatchesImageSnapshot($targetFile); -})->with('drivers'); +})->with('drivers', [0, 50, 100]); it('will throw an exception when passing an invalid blur value', function (ImageDriver $driver) { $driver->loadFile(getTestJpg())->blur(101); diff --git a/tests/Manipulations/PixelateTest.php b/tests/Manipulations/PixelateTest.php index ec5e5538..e023f22b 100644 --- a/tests/Manipulations/PixelateTest.php +++ b/tests/Manipulations/PixelateTest.php @@ -1,13 +1,18 @@ tempDir->path("{$driver->driverName()}/pixelate.png"); - $driver->loadFile(getTestJpg())->pixelate()->save($targetFile); + $driver->loadFile(getTestJpg())->pixelate($pixelate)->save($targetFile); assertMatchesImageSnapshot($targetFile); -})->with('drivers'); +})->with('drivers', [0, 50, 100]); + +it('will throw an exception when passing an invalid pixelate value', function (ImageDriver $driver) { + $driver->loadFile(getTestJpg())->pixelate(101); +})->with('drivers')->throws(InvalidManipulation::class); diff --git a/tests/Manipulations/SharpenTest.php b/tests/Manipulations/SharpenTest.php index 012dc306..57aafbd0 100644 --- a/tests/Manipulations/SharpenTest.php +++ b/tests/Manipulations/SharpenTest.php @@ -5,13 +5,13 @@ use function Spatie\Snapshots\assertMatchesImageSnapshot; -it('can sharpen an image', function (ImageDriver $driver) { +it('can sharpen an image', function (ImageDriver $driver, int $sharpen) { $targetFile = $this->tempDir->path("{$driver->driverName()}/sharpen.png"); - $driver->loadFile(getTestJpg())->sharpen(50)->save($targetFile); + $driver->loadFile(getTestJpg())->sharpen($sharpen)->save($targetFile); assertMatchesImageSnapshot($targetFile); -})->with('drivers'); +})->with('drivers', [0, 50, 100]); it('will throw an exception when passing an invalid sharpen value', function (ImageDriver $driver) { $driver->loadFile(getTestJpg())->sharpen(101);