1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-21 05:01:20 +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
* @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;

View File

@@ -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
}