1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 00:29:55 +02:00

Add Encoder Options for progressive Jpeg & interlaced GIF format

This commit is contained in:
Oliver Vogel
2024-03-27 15:30:28 +01:00
committed by GitHub
parent c261654599
commit d982359ab8
18 changed files with 203 additions and 39 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Intervention\Image\Tests\Unit\Drivers\Gd\Encoders;
use Intervention\Gif\Decoder;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Encoders\GifEncoder;
@@ -20,5 +21,30 @@ final class GifEncoderTest extends GdTestCase
$encoder = new GifEncoder();
$result = $encoder->encode($image);
$this->assertMediaType('image/gif', (string) $result);
$this->assertFalse(
Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced()
);
}
public function testEncodeInterlaced(): void
{
$image = $this->createTestImage(3, 2);
$encoder = new GifEncoder(interlaced: true);
$result = $encoder->encode($image);
$this->assertMediaType('image/gif', (string) $result);
$this->assertTrue(
Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced()
);
}
public function testEncodeInterlacedAnimation(): void
{
$image = $this->createTestAnimation(3, 2);
$encoder = new GifEncoder(interlaced: true);
$result = $encoder->encode($image);
$this->assertMediaType('image/gif', (string) $result);
$this->assertTrue(
Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced()
);
}
}

View File

@@ -8,12 +8,15 @@ use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Intervention\Image\Encoders\JpegEncoder;
use Intervention\Image\Tests\GdTestCase;
use Intervention\Image\Tests\Traits\CanDetectProgressiveJpeg;
#[RequiresPhpExtension('gd')]
#[CoversClass(\Intervention\Image\Encoders\JpegEncoder::class)]
#[CoversClass(\Intervention\Image\Drivers\Gd\Encoders\JpegEncoder::class)]
final class JpegEncoderTest extends GdTestCase
{
use CanDetectProgressiveJpeg;
public function testEncode(): void
{
$image = $this->createTestImage(3, 2);
@@ -21,4 +24,13 @@ final class JpegEncoderTest extends GdTestCase
$result = $encoder->encode($image);
$this->assertMediaType('image/jpeg', (string) $result);
}
public function testEncodeProgressive(): void
{
$image = $this->createTestImage(3, 2);
$encoder = new JpegEncoder(progressive: true);
$result = $encoder->encode($image);
$this->assertMediaType('image/jpeg', (string) $result);
$this->assertTrue($this->isProgressiveJpeg((string) $result));
}
}