mirror of
https://github.com/Intervention/image.git
synced 2025-08-30 09:10:21 +02:00
Supported format detection (#1330)
* Implement data struture for format, media types & file extensions * Refactor encoder resolving * Extend type options in encoder methods * Add DriverInterface::supports()
This commit is contained in:
@@ -15,12 +15,13 @@ use Intervention\Image\Encoders\PngEncoder;
|
||||
use Intervention\Image\Encoders\TiffEncoder;
|
||||
use Intervention\Image\Encoders\WebpEncoder;
|
||||
use Intervention\Image\Exceptions\EncoderException;
|
||||
use Intervention\Image\FileExtension;
|
||||
use Intervention\Image\Interfaces\EncoderInterface;
|
||||
use Intervention\Image\Tests\BaseTestCase;
|
||||
|
||||
final class FileExtensionEncoderTest extends BaseTestCase
|
||||
{
|
||||
private function testEncoder(string $extension): EncoderInterface
|
||||
private function testEncoder(string|FileExtension $extension): EncoderInterface
|
||||
{
|
||||
$encoder = new class () extends FileExtensionEncoder
|
||||
{
|
||||
@@ -33,9 +34,8 @@ final class FileExtensionEncoderTest extends BaseTestCase
|
||||
return $encoder->test($extension);
|
||||
}
|
||||
|
||||
public function testEncoderByFileExtension(): void
|
||||
public function testEncoderByFileExtensionString(): void
|
||||
{
|
||||
|
||||
$this->assertInstanceOf(
|
||||
WebpEncoder::class,
|
||||
$this->testEncoder('webp')
|
||||
@@ -82,6 +82,54 @@ final class FileExtensionEncoderTest extends BaseTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncoderByFileExtensionEnumMember(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
WebpEncoder::class,
|
||||
$this->testEncoder(FileExtension::WEBP)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
AvifEncoder::class,
|
||||
$this->testEncoder(FileExtension::AVIF)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
JpegEncoder::class,
|
||||
$this->testEncoder(FileExtension::JPG)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
BmpEncoder::class,
|
||||
$this->testEncoder(FileExtension::BMP)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
GifEncoder::class,
|
||||
$this->testEncoder(FileExtension::GIF)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
PngEncoder::class,
|
||||
$this->testEncoder(FileExtension::PNG)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
TiffEncoder::class,
|
||||
$this->testEncoder(FileExtension::TIF)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Jpeg2000Encoder::class,
|
||||
$this->testEncoder(FileExtension::JPG2)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
HeicEncoder::class,
|
||||
$this->testEncoder(FileExtension::HEIC)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncoderByFileExtensionUnknown(): void
|
||||
{
|
||||
$this->expectException(EncoderException::class);
|
||||
|
Reference in New Issue
Block a user