Skip to content

Commit

Permalink
added getImageInstance() method
Browse files Browse the repository at this point in the history
  • Loading branch information
mirko-pagliai committed Aug 10, 2017
1 parent 581b34a commit 955afed
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/Utility/ThumbCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ protected function getDefaultSaveOptions($options)
return $options;
}

/**
* Gets an `Image` instance
* @return \Intervention\Image\Image
* @throws InternalErrorException
* @uses $path
*/
protected function getImageInstance()
{
//Tries to create the image instance
try {
$imageInstance = (new ImageManager(['driver' => $this->getDriver()]))
->make($this->path);
} catch (NotReadableException $e) {
throw new InternalErrorException(__d('thumber', 'Unable to read image from file `{0}`', rtr($this->path)));
}

return $imageInstance;
}

/**
* Internal method to resolve a partial path, returning its full path
* @param string $path Partial path
Expand Down Expand Up @@ -236,6 +255,7 @@ public function resize($width = null, $heigth = null, array $options = [])
* @see https://github.com/mirko-pagliai/cakephp-thumber/wiki/How-to-uses-the-ThumbCreator-utility#save
* @throws InternalErrorException
* @uses getDefaultSaveOptions()
* @uses getImageInstance()
* @uses $arguments
* @uses $callbacks
* @uses $path
Expand Down Expand Up @@ -263,14 +283,7 @@ public function save(array $options = [])

//Creates the thumbnail, if this does not exist
if (!file_exists($target)) {
//Tries to create the image instance
try {
$imageInstance = (new ImageManager([
'driver' => $this->getDriver(),
]))->make($this->path);
} catch (NotReadableException $e) {
throw new InternalErrorException(__d('thumber', 'Unable to read image from file `{0}`', rtr($this->path)));
}
$imageInstance = $this->getImageInstance();

//Calls each callback
foreach ($this->callbacks as $callback) {
Expand Down

0 comments on commit 955afed

Please sign in to comment.