1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-21 13:11:18 +02:00

Change GIF detection to avoid fileinfo dependecy

This commit is contained in:
Oliver Vogel
2023-12-14 14:17:13 +01:00
parent 2622255af8
commit ac97341294
2 changed files with 9 additions and 10 deletions

View File

@@ -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 * @param string $input
* @return string * @return bool
*/ */
protected function mediaType(string $input): string protected function isGifFormat(string $input): bool
{ {
$pointer = $this->buildFilePointer($input); return preg_match(
$type = mime_content_type($pointer); "/^47494638(37|39)61/",
fclose($pointer); strtoupper(substr(bin2hex($input), 0, 32))
);
return $type;
} }
/** /**
@@ -118,7 +117,7 @@ abstract class AbstractDecoder implements DecoderInterface
$result = preg_match($pattern, $value, $matches); $result = preg_match($pattern, $value, $matches);
return new class ($matches, $result) return new class($matches, $result)
{ {
private $matches; private $matches;
private $result; private $result;

View File

@@ -22,7 +22,7 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
throw new DecoderException('Unable to decode input'); throw new DecoderException('Unable to decode input');
} }
if ($this->mediaType($input) == 'image/gif') { if ($this->isGifFormat($input)) {
return $this->decodeGif($input); // decode (animated) gif return $this->decodeGif($input); // decode (animated) gif
} }