1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-08 05:00:41 +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 public function supports(string|Format|FileExtension|MediaType $identifier): bool
{ {
try { return match (Format::tryCreate($identifier)) {
$format = Format::create($identifier);
} catch (NotSupportedException) {
return false;
}
return match ($format) {
Format::JPEG => boolval(imagetypes() & IMG_JPEG), Format::JPEG => boolval(imagetypes() & IMG_JPEG),
Format::WEBP => boolval(imagetypes() & IMG_WEBP), Format::WEBP => boolval(imagetypes() & IMG_WEBP),
Format::GIF => boolval(imagetypes() & IMG_GIF), Format::GIF => boolval(imagetypes() & IMG_GIF),

View File

@@ -10,7 +10,6 @@ use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Format; use Intervention\Image\Format;
use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\MediaType;
class BinaryImageDecoder extends NativeObjectDecoder class BinaryImageDecoder extends NativeObjectDecoder
{ {
@@ -31,10 +30,10 @@ class BinaryImageDecoder extends NativeObjectDecoder
$image = parent::decode($imagick); $image = parent::decode($imagick);
// get media type enum from string media type // 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 // 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)); $image->setExif($this->extractExifData($input));
} }