Skip to content

Commit

Permalink
Change GIF detection to avoid fileinfo dependecy
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 14, 2023
1 parent 2622255 commit ac97341
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/Drivers/AbstractDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,17 @@ protected function hasSuccessor(): bool
}

/**
* 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))
);
}

/**
Expand Down Expand Up @@ -118,7 +117,7 @@ protected function parseDataUri($value): object

$result = preg_match($pattern, $value, $matches);

return new class ($matches, $result)
return new class($matches, $result)
{
private $matches;
private $result;
Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/Gd/Decoders/BinaryImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function decode($input): ImageInterface|ColorInterface
throw new DecoderException('Unable to decode input');
}

if ($this->mediaType($input) == 'image/gif') {
if ($this->isGifFormat($input)) {
return $this->decodeGif($input); // decode (animated) gif
}

Expand Down

0 comments on commit ac97341

Please sign in to comment.