Skip to content

Commit

Permalink
Only use getimagesize() for GIFs, JPGs and PNGs.
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Nov 16, 2016
1 parent 9a3f206 commit f459225
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Image.php
Expand Up @@ -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;
}

Expand Down

0 comments on commit f459225

Please sign in to comment.