1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-16 19:58:14 +01:00

Add method Format::mediaType()

This commit is contained in:
Oliver Vogel 2024-10-06 17:07:06 +02:00
parent cfa0986afe
commit 4a5a7f6065
No known key found for this signature in database
GPG Key ID: 1B19D214C02D69BB
2 changed files with 30 additions and 0 deletions

View File

@ -91,6 +91,18 @@ enum Format
});
}
/**
* Return the first found media type for the current format
*
* @return MediaType
*/
public function mediaType(): MediaType
{
$types = $this->mediaTypes();
return reset($types);
}
/**
* Return the possible file extension for the current format
*

View File

@ -56,6 +56,8 @@ final class FormatTest extends BaseTestCase
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(4, $mediaTypes);
$this->assertEquals(MediaType::IMAGE_JPEG, $format->mediaType());
}
public function testMediaTypesWebp(): void
@ -64,6 +66,8 @@ final class FormatTest extends BaseTestCase
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(2, $mediaTypes);
$this->assertEquals(MediaType::IMAGE_WEBP, $format->mediaType());
}
public function testMediaTypesFGif(): void
@ -72,6 +76,8 @@ final class FormatTest extends BaseTestCase
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(1, $mediaTypes);
$this->assertEquals(MediaType::IMAGE_GIF, $format->mediaType());
}
public function testMediaTypesPng(): void
@ -80,6 +86,8 @@ final class FormatTest extends BaseTestCase
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(2, $mediaTypes);
$this->assertEquals(MediaType::IMAGE_PNG, $format->mediaType());
}
public function testMediaTypesAvif(): void
@ -88,6 +96,8 @@ final class FormatTest extends BaseTestCase
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(2, $mediaTypes);
$this->assertEquals(MediaType::IMAGE_AVIF, $format->mediaType());
}
public function testMediaTypesBmp(): void
@ -96,6 +106,8 @@ final class FormatTest extends BaseTestCase
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(8, $mediaTypes);
$this->assertEquals(MediaType::IMAGE_BMP, $format->mediaType());
}
public function testMediaTypesTiff(): void
@ -104,6 +116,8 @@ final class FormatTest extends BaseTestCase
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(1, $mediaTypes);
$this->assertEquals(MediaType::IMAGE_TIFF, $format->mediaType());
}
public function testMediaTypesJpeg2000(): void
@ -112,6 +126,8 @@ final class FormatTest extends BaseTestCase
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(3, $mediaTypes);
$this->assertEquals(MediaType::IMAGE_JP2, $format->mediaType());
}
public function testMediaTypesHeic(): void
@ -120,6 +136,8 @@ final class FormatTest extends BaseTestCase
$mediaTypes = $format->mediaTypes();
$this->assertIsArray($mediaTypes);
$this->assertCount(3, $mediaTypes);
$this->assertEquals(MediaType::IMAGE_HEIC, $format->mediaType());
}
public function testEncoderJpeg(): void