diff --git a/src/Drivers/AbstractDecoder.php b/src/Drivers/AbstractDecoder.php index b8e4a195..71b02d32 100644 --- a/src/Drivers/AbstractDecoder.php +++ b/src/Drivers/AbstractDecoder.php @@ -53,18 +53,17 @@ abstract class AbstractDecoder implements DecoderInterface } /** - * Return media type (MIME) of given input + * Determine if the given input is GIF data format * * @param string $input - * @return string + * @return bool */ - protected function mediaType(string $input): string + protected function isGifFormat(string $input): bool { - $pointer = $this->buildFilePointer($input); - $type = mime_content_type($pointer); - fclose($pointer); - - return $type; + return preg_match( + "/^47494638(37|39)61/", + strtoupper(substr(bin2hex($input), 0, 32)) + ); } /** @@ -118,7 +117,7 @@ abstract class AbstractDecoder implements DecoderInterface $result = preg_match($pattern, $value, $matches); - return new class ($matches, $result) + return new class($matches, $result) { private $matches; private $result; diff --git a/src/Drivers/Gd/Decoders/BinaryImageDecoder.php b/src/Drivers/Gd/Decoders/BinaryImageDecoder.php index 00500b18..41113756 100644 --- a/src/Drivers/Gd/Decoders/BinaryImageDecoder.php +++ b/src/Drivers/Gd/Decoders/BinaryImageDecoder.php @@ -22,7 +22,7 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface throw new DecoderException('Unable to decode input'); } - if ($this->mediaType($input) == 'image/gif') { + if ($this->isGifFormat($input)) { return $this->decodeGif($input); // decode (animated) gif }