Skip to content

Commit

Permalink
Added try catch handler to fetch exceptions when requesting getimages… (
Browse files Browse the repository at this point in the history
#13)

* Added try catch handler to fetch exceptions when requesting getimagesize.

* Logging error (if logger exists) if getimagesize is empty.
  • Loading branch information
sn4h authored and camspiers committed May 11, 2016
1 parent f71832d commit b8def03
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions code/ImageOptimiserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ public function setLogger($logger)
public function optimiseImage($filename)
{
if (file_exists($filename)) {
list($width, $height, $type, $attr) = getimagesize($filename);
$size = @getimagesize($filename);
if (!is_array($size)) {
if (null !== $this->logger) {
$this->logger->error("Error reading file when attempting to optimize");
}
return;
}
list($width, $height, $type, $attr) = $size;

$commands = $this->getCommands($filename, $type = $this->getImageType($type));

Expand Down Expand Up @@ -139,4 +146,4 @@ private function execCommand($command)

return $process;
}
}
}

0 comments on commit b8def03

Please sign in to comment.