Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in ImagickDriver::pixelate, Update tests #267

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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