|
|
@@ -51,6 +51,8 @@ class ImageServiceProviderLaravel5 extends ServiceProvider
|
|
|
$app['image'] = $app->share(function ($app) {
|
|
|
return new ImageManager($app['config']->get('image'));
|
|
|
});
|
|
|
+
|
|
|
+ $app->alias('image', 'Intervention\Image\ImageManager');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -73,63 +75,16 @@ class ImageServiceProviderLaravel5 extends ServiceProvider
|
|
|
'imagecache'
|
|
|
);
|
|
|
|
|
|
- $config = $app['config'];
|
|
|
-
|
|
|
- // create dynamic manipulation route
|
|
|
- if (is_string($config->get('imagecache.route'))) {
|
|
|
-
|
|
|
- // add original to route templates
|
|
|
- $config->set('imagecache.templates.original', null);
|
|
|
-
|
|
|
- $app['router']->get($config->get('imagecache.route').'/{template}/{filename}', array('as' => 'imagecache', function ($template, $filename) use ($app, $config) {
|
|
|
-
|
|
|
-
|
|
|
- // disable session cookies for image route
|
|
|
- $app['config']->set('session.driver', 'array');
|
|
|
-
|
|
|
- // find file
|
|
|
- foreach ($config->get('imagecache.paths') as $path) {
|
|
|
- // don't allow '..' in filenames
|
|
|
- $image_path = $path.'/'.str_replace('..', '', $filename);
|
|
|
- if (file_exists($image_path) && is_file($image_path)) {
|
|
|
- break;
|
|
|
- } else {
|
|
|
- $image_path = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // abort if file not found
|
|
|
- if ($image_path === false) {
|
|
|
- $app->abort(404);
|
|
|
- }
|
|
|
-
|
|
|
- // define template callback
|
|
|
- $callback = $config->get("imagecache.templates.{$template}");
|
|
|
-
|
|
|
- if (is_callable($callback)) {
|
|
|
-
|
|
|
- // image manipulation based on callback
|
|
|
- $content = $app['image']->cache(function ($image) use ($image_path, $callback) {
|
|
|
- return $callback($image->make($image_path));
|
|
|
- }, $config->get('imagecache.lifetime'));
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- // get original image file contents
|
|
|
- $content = file_get_contents($image_path);
|
|
|
- }
|
|
|
-
|
|
|
- // define mime type
|
|
|
- $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content);
|
|
|
+ // imagecache route
|
|
|
+ if (is_string(config('imagecache.route'))) {
|
|
|
|
|
|
- // return http response
|
|
|
- return new IlluminateResponse($content, 200, array(
|
|
|
- 'Content-Type' => $mime,
|
|
|
- 'Cache-Control' => 'max-age='.($config->get('imagecache.lifetime')*60).', public',
|
|
|
- 'Etag' => md5($content)
|
|
|
- ));
|
|
|
+ $filename_pattern = '[ \w\\.\\/\\-]+';
|
|
|
|
|
|
- }))->where(array('template' => join('|', array_keys($config->get('imagecache.templates'))), 'filename' => '[ \w\\.\\/\\-]+'));
|
|
|
+ // route to access template applied image file
|
|
|
+ $app['router']->get(config('imagecache.route').'/{template}/{filename}', array(
|
|
|
+ 'uses' => 'Intervention\Image\ImageCacheController@getResponse',
|
|
|
+ 'as' => 'imagecache'
|
|
|
+ ))->where(array('filename' => $filename_pattern));
|
|
|
}
|
|
|
}
|
|
|
}
|