1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-26 07:14:31 +02:00

Added gamma modifier

This commit is contained in:
Oliver Vogel
2022-02-11 19:17:15 +01:00
parent 51e4fdb7e6
commit a1a07ac1e7
5 changed files with 101 additions and 0 deletions

View File

@@ -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(

View 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;
}
}

View 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;
}
}

View 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());
}
}

View 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());
}
}