Skip to content

Commit

Permalink
merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Sep 5, 2023
2 parents 8f23fe1 + d81506d commit f38fbac
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Drivers/Concerns/ValidatesArguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

trait ValidatesArguments
{
protected function ensureNumberBetween(int $value, int $min, int $max, string $label): void
protected function ensureNumberBetween(int|float $value, int|float $min, int|float $max, string $label): void
{
if ($value < $min || $value > $max) {
throw InvalidManipulation::valueNotInRange($label, $value, $min, $max);
Expand Down
18 changes: 18 additions & 0 deletions src/Drivers/GdImageDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,22 @@ public function resizeCanvas(

return $this;
}

public function gamma(float $gamma): ImageDriver
{
$this->ensureNumberBetween($gamma, 0.1, 9.99, 'gamma');

imagegammacorrect($this->image, 1, $gamma);

return $this;
}

public function contrast(float $level): ImageDriver
{
$this->ensureNumberBetween($level, -100, 100, 'contrast');

imagefilter($this->image, IMG_FILTER_CONTRAST, ($level * -1));

return $this;
}
}
18 changes: 18 additions & 0 deletions src/Drivers/ImagickImageDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,22 @@ public function getSize(): Size
{
return new Size($this->getWidth(), $this->getHeight());
}

public function gamma(float $gamma): ImageDriver
{
$this->ensureNumberBetween($gamma, 0.1, 9.99, 'gamma');

$this->image->gammaImage($gamma);

return $this;
}

public function contrast(float $level): ImageDriver
{
$this->ensureNumberBetween($level, -100, 100, 'contrast');

$this->image->brightnessContrastImage(1, $level);

return $this;
}
}
18 changes: 18 additions & 0 deletions tests/Manipulations/ContrastTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Spatie\Image\Test\Manipulations;

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

it('can change the contrast of an image', function (ImageDriver $driver) {
$targetFile = $this->tempDir->path("{$driver->driverName()}/contrast.jpg");

$driver->load(getTestPhoto())->contrast(30)->save($targetFile);

expect($targetFile)->toBeFile();
})->with('drivers');

it('will throw an exception when passing an invalid contrast value', function (ImageDriver $driver) {
$driver->load(getTestPhoto())->brightness(101);
})->with('drivers')->throws(InvalidManipulation::class);
13 changes: 13 additions & 0 deletions tests/Manipulations/GammaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Spatie\Image\Test\Manipulations;

use Spatie\Image\Drivers\ImageDriver;

it('can apply gamma to an image', function (ImageDriver $driver) {
$targetFile = $this->tempDir->path("{$driver->driverName()}/gamma.jpg");

$driver->load(getTestJpg())->gamma(4.8)->save($targetFile);

expect($targetFile)->toBeFile();
})->with('drivers');
5 changes: 5 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ function getTestJpg(): string
return getTestFile('test.jpg');
}

function getTestPhoto(): string
{
return getTestFile('test-photo.jpg');
}

function getTestFile($fileName): string
{
return getTestSupportPath('testFiles/'.$fileName);
Expand Down
Binary file added tests/TestSupport/testFiles/test-photo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f38fbac

Please sign in to comment.