mirror of
https://github.com/Intervention/image.git
synced 2025-08-26 15:24:37 +02:00
Added gamma modifier
This commit is contained in:
@@ -139,6 +139,13 @@ abstract class AbstractImage
|
||||
);
|
||||
}
|
||||
|
||||
public function gamma(float $gamma): ImageInterface
|
||||
{
|
||||
return $this->modify(
|
||||
$this->resolveDriverClass('Modifiers\GammaModifier', $gamma)
|
||||
);
|
||||
}
|
||||
|
||||
public function blur(int $amount = 5): ImageInterface
|
||||
{
|
||||
return $this->modify(
|
||||
|
23
src/Drivers/Gd/Modifiers/GammaModifier.php
Normal file
23
src/Drivers/Gd/Modifiers/GammaModifier.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
|
||||
class GammaModifier implements ModifierInterface
|
||||
{
|
||||
public function __construct(protected float $gamma)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function apply(ImageInterface $image): ImageInterface
|
||||
{
|
||||
foreach ($image as $frame) {
|
||||
imagegammacorrect($frame->getCore(), 1, $this->gamma);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
}
|
23
src/Drivers/Imagick/Modifiers/GammaModifier.php
Normal file
23
src/Drivers/Imagick/Modifiers/GammaModifier.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
||||
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
|
||||
class GammaModifier implements ModifierInterface
|
||||
{
|
||||
public function __construct(protected float $gamma)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function apply(ImageInterface $image): ImageInterface
|
||||
{
|
||||
foreach ($image as $frame) {
|
||||
$frame->getCore()->gammaImage($this->gamma);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
}
|
24
tests/Drivers/Gd/Modifiers/GammaModifierTest.php
Normal file
24
tests/Drivers/Gd/Modifiers/GammaModifierTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers;
|
||||
|
||||
use Intervention\Image\Drivers\Gd\Modifiers\GammaModifier;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
||||
|
||||
/**
|
||||
* @requires extension gd
|
||||
* @covers \Intervention\Image\Drivers\Gd\Modifiers\GammaModifier
|
||||
*/
|
||||
class GammaModifierTest extends TestCase
|
||||
{
|
||||
use CanCreateGdTestImage;
|
||||
|
||||
public function testModifier(): void
|
||||
{
|
||||
$image = $this->createTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
|
||||
$image->modify(new GammaModifier(2.1));
|
||||
$this->assertEquals('00d5f8', $image->pickColor(0, 0)->toHex());
|
||||
}
|
||||
}
|
24
tests/Drivers/Imagick/Modifiers/GammaModifierTest.php
Normal file
24
tests/Drivers/Imagick/Modifiers/GammaModifierTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers;
|
||||
|
||||
use Intervention\Image\Drivers\Imagick\Modifiers\GammaModifier;
|
||||
use Intervention\Image\Tests\TestCase;
|
||||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||
|
||||
/**
|
||||
* @requires extension imagick
|
||||
* @covers \Intervention\Image\Drivers\Imagick\Modifiers\GammaModifier
|
||||
*/
|
||||
class GammaModifierTest extends TestCase
|
||||
{
|
||||
use CanCreateImagickTestImage;
|
||||
|
||||
public function testModifier(): void
|
||||
{
|
||||
$image = $this->createTestImage('trim.png');
|
||||
$this->assertEquals('00aef0', $image->pickColor(0, 0)->toHex());
|
||||
$image->modify(new GammaModifier(2.1));
|
||||
$this->assertEquals('00d5f8', $image->pickColor(0, 0)->toHex());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user