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). + diff --git a/composer.json b/composer.json index 82dc4b2..f1620ce 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": "~6|~7|~8|~9", + "illuminate/filesystem": "~6|~7|~8|~9", + "jeremeamia/superclosure": "~1|~2" }, "require-dev": { "phpunit/phpunit": "3.*", diff --git a/src/Intervention/Image/ImageCacheController.php b/src/Intervention/Image/ImageCacheController.php index 5e53861..5116280 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); } @@ -55,7 +56,7 @@ public function getImage($template, $filename) // build from filter template $image->make($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, );