From f459225c6d223317f05d4b4a01a6165b0c206b9a Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Wed, 16 Nov 2016 16:32:32 +0100 Subject: [PATCH] Only use getimagesize() for GIFs, JPGs and PNGs. --- src/Image.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Image.php b/src/Image.php index 268cf8b..9656c14 100644 --- a/src/Image.php +++ b/src/Image.php @@ -111,16 +111,24 @@ public function getUrl($rootDir, $prefix = '') */ public function getDimensions() { + // Try native getimagesize() for better performance if (null === $this->dimensions) { - $size = @getimagesize($this->getPath()); // try native getimagesize() for better performance + $ext = pathinfo($this->getPath(), PATHINFO_EXTENSION); - if (!empty($size[0]) && !empty($size[1])) { - $this->dimensions = new ImageDimensions(new Box($size[0], $size[1])); - } else { - $this->dimensions = new ImageDimensions($this->imagine->open($this->getPath())->getSize()); + if (in_array($ext, ['gif', 'jpg', 'jpeg', 'png'])) { + $size = @getimagesize($this->getPath()); + + if (!empty($size[0]) && !empty($size[1])) { + $this->dimensions = new ImageDimensions(new Box($size[0], $size[1])); + } } } + // Fall back to Imagine + if (null === $this->dimensions) { + $this->dimensions = new ImageDimensions($this->imagine->open($this->getPath())->getSize()); + } + return $this->dimensions; }