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

Refactor format detection

This commit is contained in:
Oliver Vogel
2024-07-03 16:52:54 +02:00
parent f130eb0985
commit 75ab2c2225
2 changed files with 3 additions and 10 deletions

View File

@@ -140,13 +140,7 @@ class Driver extends AbstractDriver
*/
public function supports(string|Format|FileExtension|MediaType $identifier): bool
{
try {
$format = Format::create($identifier);
} catch (NotSupportedException) {
return false;
}
return match ($format) {
return match (Format::tryCreate($identifier)) {
Format::JPEG => boolval(imagetypes() & IMG_JPEG),
Format::WEBP => boolval(imagetypes() & IMG_WEBP),
Format::GIF => boolval(imagetypes() & IMG_GIF),

View File

@@ -10,7 +10,6 @@ use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Format;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\MediaType;
class BinaryImageDecoder extends NativeObjectDecoder
{
@@ -31,10 +30,10 @@ class BinaryImageDecoder extends NativeObjectDecoder
$image = parent::decode($imagick);
// get media type enum from string media type
$mediaType = MediaType::from($image->origin()->mediaType());
$format = Format::tryCreate($image->origin()->mediaType());
// extract exif data for appropriate formats
if (in_array($mediaType->format(), [Format::JPEG, Format::TIFF])) {
if (in_array($format, [Format::JPEG, Format::TIFF])) {
$image->setExif($this->extractExifData($input));
}