Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Support Laravel FileSystems #90

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ $img = Image::cache(function($image) {
## License

Intervention Imagecache Class is licensed under the [MIT License](http://opensource.org/licenses/MIT).

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*",
Expand Down
48 changes: 40 additions & 8 deletions src/Intervention/Image/ImageCacheController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Response as IlluminateResponse;
use Config;
use Storage;

class ImageCacheController extends BaseController
{
Expand All @@ -26,7 +27,7 @@ public function getResponse($template, $filename)

case 'download':
return $this->getDownload($filename);

default:
return $this->getImage($template, $filename);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -108,7 +109,7 @@ protected function getTemplate($template)
// filter template found
case class_exists($template):
return new $template;

default:
// template not found
abort(404);
Expand All @@ -126,22 +127,53 @@ 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";
}
}

// file not found
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)
Expand Down
28 changes: 16 additions & 12 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,34 @@
|
| 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,

/*
|--------------------------------------------------------------------------
| 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.
| <disk>:<path>
|
| 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'
),

/*
Expand All @@ -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}
Expand All @@ -50,7 +54,7 @@
| will be applied, by its fully qualified name.
|
*/

'templates' => array(
'small' => 'Intervention\Image\Templates\Small',
'medium' => 'Intervention\Image\Templates\Medium',
Expand All @@ -65,7 +69,7 @@
| Lifetime in minutes of the images handled by the imagecache route.
|
*/

'lifetime' => 43200,

);