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:
@@ -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),
|
||||||
|
@@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user