1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-24 06:22:57 +02:00

Trim Modifier (#1322)

Co-authored-by: Sibin Grasic <sibin.grasic@oblak.studio>
This commit is contained in:
Oliver Vogel
2024-03-25 19:46:16 +01:00
committed by GitHub
parent dffb2bb4fe
commit f035f7d516
8 changed files with 254 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Modifiers;
use Intervention\Image\Exceptions\NotSupportedException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Modifiers\TrimModifier;
use Intervention\Image\Tests\GdTestCase;
#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Modifiers\TrimModifier::class)]
#[CoversClass(\Intervention\Image\Drivers\Gd\Modifiers\TrimModifier::class)]
final class TrimModifierTest extends GdTestCase
{
public function testTrim(): void
{
$image = $this->readTestImage('trim.png');
$this->assertEquals(50, $image->width());
$this->assertEquals(50, $image->height());
$image->modify(new TrimModifier());
$this->assertEquals(28, $image->width());
$this->assertEquals(28, $image->height());
}
public function testTrimGradient(): void
{
$image = $this->readTestImage('radial.png');
$this->assertEquals(50, $image->width());
$this->assertEquals(50, $image->height());
$image->modify(new TrimModifier(50));
$this->assertEquals(35, $image->width());
$this->assertEquals(35, $image->height());
}
public function testTrimHighTolerance(): void
{
$image = $this->readTestImage('trim.png');
$this->assertEquals(50, $image->width());
$this->assertEquals(50, $image->height());
$image->modify(new TrimModifier(1000000));
$this->assertEquals(1, $image->width());
$this->assertEquals(1, $image->height());
$this->assertColor(255, 255, 255, 0, $image->pickColor(0, 0));
}
public function testTrimAnimated(): void
{
$image = $this->readTestImage('animation.gif');
$this->expectException(NotSupportedException::class);
$image->modify(new TrimModifier());
}
}