Skip to content

Commit

Permalink
Fix bug in ImagickDriver::pixelate, Update tests (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
psion-ar authored Jul 18, 2024
1 parent 42dff38 commit 1151c32
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/Drivers/Imagick/ImagickDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions tests/Manipulations/BlurTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions tests/Manipulations/PixelateTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?php

use Spatie\Image\Drivers\ImageDriver;
use Spatie\Image\Exceptions\InvalidManipulation;

use function Spatie\Snapshots\assertMatchesImageSnapshot;

it('can pixelate an image', function (ImageDriver $driver) {
it('can pixelate an image', function (ImageDriver $driver, int $pixelate) {
$targetFile = $this->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);
6 changes: 3 additions & 3 deletions tests/Manipulations/SharpenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1151c32

Please sign in to comment.