5 use Illuminate\Support\ServiceProvider;
6 use Illuminate\Http\Response
as IlluminateResponse;
17 $this->package(
'intervention/image');
20 if (class_exists(
'Intervention\\Image\\ImageCache')) {
25 $app[
'config']->package(
'intervention/imagecache', __DIR__.
'/../../../../imagecache/src/config',
'imagecache');
29 if (is_string(
$config->get(
'imagecache::route'))) {
32 $config->set(
'imagecache::templates.original',
null);
35 $app[
'router']->get(
$config->get(
'imagecache::route').
'/{template}/{filename}', array(
'as' =>
'imagecache',
function ($template, $filename)
use ($app,
$config) {
38 $app[
'config']->set(
'session.driver',
'array');
43 $image_path = $path.
'/'.str_replace(
'..',
'', $filename);
44 if (file_exists($image_path) && is_file($image_path)) {
52 if ($image_path ===
false) {
57 $callback =
$config->get(
"imagecache::templates.{$template}");
59 if (is_callable($callback)) {
62 $content = $app[
'image']->cache(
function ($image)
use ($image_path, $callback) {
63 return $callback($image->make($image_path));
64 },
$config->get(
'imagecache::lifetime'));
69 $content = file_get_contents($image_path);
73 $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $content);
76 return new IlluminateResponse($content, 200, array(
77 'Content-Type' => $mime,
78 'Cache-Control' =>
'max-age='.(
$config->get(
'imagecache::lifetime')*60).
', public',
79 'Etag' => md5($content)
82 }))->where(array(
'template' => join(
'|', array_keys(
$config->get(
'imagecache::templates'))),
'filename' =>
'[ \w\\.\\/\\-]+'));
92 public function register()
96 $app[
'image'] = $app->share(
function ($app) {
97 return new ImageManager($app[
'config']->
get(
'image::config'));
100 $app->alias(
'image',
'Intervention\Image\ImageManager');