From 955afed44e93d01b7c690ba5372f8f73b6f668e1 Mon Sep 17 00:00:00 2001 From: mirko-pagliai Date: Thu, 10 Aug 2017 19:03:17 +0200 Subject: [PATCH] added `getImageInstance()` method --- src/Utility/ThumbCreator.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Utility/ThumbCreator.php b/src/Utility/ThumbCreator.php index e19fa91..5a2b1c8 100644 --- a/src/Utility/ThumbCreator.php +++ b/src/Utility/ThumbCreator.php @@ -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 @@ -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 @@ -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) {