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