diff --git a/src/IcoParser.php b/src/IcoParser.php index 3905101..404bb54 100644 --- a/src/IcoParser.php +++ b/src/IcoParser.php @@ -16,7 +16,7 @@ class IcoParser implements ParserInterface public function isSupportedBinaryString($data) { $supported = !is_null($this->parseIconDir($data)); - $supported = $supported || $this->isPNG($data); + $supported = $supported || $this->isPNG($data) || $this->isBMP($data); return $supported; } @@ -44,13 +44,23 @@ private function isPNG($data) return ($signature['FourCC'] == 0x474e5089); } + /** + * @param $data + * @return bool true if mime type matches a BMP + */ + private function isBMP($data) + { + $signature = getimagesizefromstring($data); + return ($signature['mime'] == 'image/bmp'); + } + /** * @inheritdoc */ public function parse($data) { - if ($this->isPNG($data)) { - return $this->parsePNGAsIco($data); + if ($this->isPNG($data) || $this->isBMP($data)) { + return $this->parseImgAsIco($data); } return $this->parseICO($data); } @@ -82,13 +92,13 @@ private function parseICO($data) return $icon; } - private function parsePNGAsIco($data) + private function parseImgAsIco($data) { - $png = imagecreatefromstring($data); - $w = imagesx($png); - $h = imagesy($png); - $bits = imageistruecolor($png) ? 32 : 8; - imagedestroy($png); + $img = imagecreatefromstring($data); + $w = imagesx($img); + $h = imagesy($img); + $bits = imageistruecolor($img) ? 32 : 8; + imagedestroy($img); //fake enough header data for IconImage to do its job $icoDirEntry = [