From ec00fae820ea57f60dcb638c23771dfeeb024005 Mon Sep 17 00:00:00 2001 From: Chris Baldwin Date: Thu, 8 Mar 2018 14:15:35 -0800 Subject: [PATCH 1/5] Modify the ImageCacheController to use the Storage system to load the images. --- .../Image/ImageCacheController.php | 52 +++++++++++++++---- src/config/config.php | 28 +++++----- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/Intervention/Image/ImageCacheController.php b/src/Intervention/Image/ImageCacheController.php index 5e53861..41a9814 100644 --- a/src/Intervention/Image/ImageCacheController.php +++ b/src/Intervention/Image/ImageCacheController.php @@ -7,6 +7,7 @@ use Illuminate\Routing\Controller as BaseController; use Illuminate\Http\Response as IlluminateResponse; use Config; +use Storage; class ImageCacheController extends BaseController { @@ -26,7 +27,7 @@ public function getResponse($template, $filename) case 'download': return $this->getDownload($filename); - + default: return $this->getImage($template, $filename); } @@ -50,12 +51,12 @@ public function getImage($template, $filename) if ($template instanceof Closure) { // build from closure callback template - $template($image->make($path)); + $template($image->make(self::getImageData($path))); } else { // build from filter template - $image->make($path)->filter($template); + $image->make(self::getImageData($path))->filter($template); } - + }, config('imagecache.lifetime')); return $this->buildResponse($content); @@ -71,7 +72,7 @@ public function getOriginal($filename) { $path = $this->getImagePath($filename); - return $this->buildResponse(file_get_contents($path)); + return $this->buildResponse(self::getImageData($path)); } /** @@ -108,7 +109,7 @@ protected function getTemplate($template) // filter template found case class_exists($template): return new $template; - + default: // template not found abort(404); @@ -126,11 +127,13 @@ protected function getImagePath($filename) { // find file foreach (config('imagecache.paths') as $path) { + list($fs, $dir) = self::parsePath($path); + $disk = Storage::disk($fs); // don't allow '..' in filenames - $image_path = $path.'/'.str_replace('..', '', $filename); - if (file_exists($image_path) && is_file($image_path)) { + $image_path = $dir.'/'.str_replace('..', '', $filename); + if ($disk->exists($image_path)) { // file found - return $image_path; + return "$fs:$image_path"; } } @@ -138,10 +141,39 @@ protected function getImagePath($filename) abort(404); } + /** + * Parse a path string. + * + * @param path a path string + * @return array the path components [ 0 => disk name, 1 => file path ] + */ + private static function parsePath($path) + { + $fs = 'local'; + $dir = $path; + if (preg_match('/(.*):(.*)/', $path, $matches) === 1) { + list(, $fs, $dir) = $matches; + } + + return [$fs, $dir]; + } + + /** + * Load the image data via the Storage subsystem. + * + * @param image_path the path to the image from getImagePath() + */ + private static function getImageData($image_path) + { + list($fs, $path) = self::parsePath($image_path); + + return Storage::disk($fs)->get($path); + } + /** * Builds HTTP response from given image data * - * @param string $content + * @param string $content * @return Illuminate\Http\Response */ protected function buildResponse($content) diff --git a/src/config/config.php b/src/config/config.php index d227f51..f9db13a 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -9,13 +9,13 @@ | | Enter the routes name to enable dynamic imagecache manipulation. | This handle will define the first part of the URI: - | + | | {route}/{template}/{filename} - | + | | Examples: "images", "img/cache" | */ - + 'route' => null, /* @@ -23,16 +23,20 @@ | Storage paths |-------------------------------------------------------------------------- | - | The following paths will be searched for the image filename, submitted - | by URI. - | + | The following paths will be searched for the image filename, submitted + | by URI. + | + | Uses the File Storage system. + | : + | | Define as many directories as you like. | */ - + 'paths' => array( - public_path('upload'), - public_path('images') + 'public:upload', // Uses the public disk as defined in Storage + 'public:images', + 'images' // If no disk is specified it will default to 'local' ), /* @@ -41,7 +45,7 @@ |-------------------------------------------------------------------------- | | Here you may specify your own manipulation filter templates. - | The keys of this array will define which templates + | The keys of this array will define which templates | are available in the URI: | | {route}/{template}/{filename} @@ -50,7 +54,7 @@ | will be applied, by its fully qualified name. | */ - + 'templates' => array( 'small' => 'Intervention\Image\Templates\Small', 'medium' => 'Intervention\Image\Templates\Medium', @@ -65,7 +69,7 @@ | Lifetime in minutes of the images handled by the imagecache route. | */ - + 'lifetime' => 43200, ); From 32ddc1cae034dc6e3ed491a27acdc8245033ac06 Mon Sep 17 00:00:00 2001 From: Chris Baldwin Date: Fri, 9 Mar 2018 16:33:23 -0800 Subject: [PATCH 2/5] Remove the image loading from the cache callback to avoid loading the image when there is already an entry in the cache. --- src/Intervention/Image/ImageCacheController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Intervention/Image/ImageCacheController.php b/src/Intervention/Image/ImageCacheController.php index 41a9814..5116280 100644 --- a/src/Intervention/Image/ImageCacheController.php +++ b/src/Intervention/Image/ImageCacheController.php @@ -51,10 +51,10 @@ public function getImage($template, $filename) if ($template instanceof Closure) { // build from closure callback template - $template($image->make(self::getImageData($path))); + $template($image->make($path)); } else { // build from filter template - $image->make(self::getImageData($path))->filter($template); + $image->make($path)->filter($template); } }, config('imagecache.lifetime')); From 2dbc569411f970435b438dbe56c24794433de29f Mon Sep 17 00:00:00 2001 From: Hans Andersen Date: Tue, 20 Jul 2021 17:12:23 -0700 Subject: [PATCH 3/5] Test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 064c5a0..2abd8df 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,4 @@ $img = Image::cache(function($image) { ## License Intervention Imagecache Class is licensed under the [MIT License](http://opensource.org/licenses/MIT). + From e4f497cf3886f220e18fa1dd9334dbe73e0abaa3 Mon Sep 17 00:00:00 2001 From: Hans Andersen Date: Tue, 22 Feb 2022 18:14:22 -0800 Subject: [PATCH 4/5] Update dependencies --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 82dc4b2..4de2444 100644 --- a/composer.json +++ b/composer.json @@ -14,9 +14,9 @@ "require": { "php": ">=5.3.0", "intervention/image": "dev-master|~2,>=2.2.0", - "illuminate/cache": "~4|~5", - "illuminate/filesystem": "~4|~5", - "jeremeamia/SuperClosure": "~1|~2" + "illuminate/cache": "^5.5|~6|~7|~8|~9", + "illuminate/filesystem": "^5.5|~6|~7|~8|~9", + "jeremeamia/superclosure": "~1|~2" }, "require-dev": { "phpunit/phpunit": "3.*", From 7e3a474e16cf548c421b298bfdd7cef0fcefc88d Mon Sep 17 00:00:00 2001 From: Hans Andersen Date: Tue, 22 Feb 2022 18:18:52 -0800 Subject: [PATCH 5/5] Update dependencies --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4de2444..f1620ce 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ "require": { "php": ">=5.3.0", "intervention/image": "dev-master|~2,>=2.2.0", - "illuminate/cache": "^5.5|~6|~7|~8|~9", - "illuminate/filesystem": "^5.5|~6|~7|~8|~9", + "illuminate/cache": "~6|~7|~8|~9", + "illuminate/filesystem": "~6|~7|~8|~9", "jeremeamia/superclosure": "~1|~2" }, "require-dev": {