From 420500e68dcf16c1eec66767330d685c5a077c53 Mon Sep 17 00:00:00 2001 From: Arjan Kempes Date: Wed, 27 Jul 2016 21:27:57 +0200 Subject: [PATCH 1/2] Added args variable in applyFilter function to support template variables --- .../Image/ImageCacheController.php | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Intervention/Image/ImageCacheController.php b/src/Intervention/Image/ImageCacheController.php index 7fca05d..a22fe59 100644 --- a/src/Intervention/Image/ImageCacheController.php +++ b/src/Intervention/Image/ImageCacheController.php @@ -41,19 +41,19 @@ public function getResponse($template, $filename) */ public function getImage($template, $filename) { - $template = $this->getTemplate($template); + list($template, $args) = $this->getTemplate($template); $path = $this->getImagePath($filename); // image manipulation based on callback $manager = new ImageManager(Config::get('image')); - $content = $manager->cache(function ($image) use ($template, $path) { + $content = $manager->cache(function ($image) use ($template, $args, $path) { if ($template instanceof Closure) { // build from closure callback template - $template($image->make($path)); + $template($image->make($path), $args); } else { // build from filter template - $image->make($path)->filter($template); + $image->make($path)->filter($template, $args); } }, config('imagecache.lifetime')); @@ -98,16 +98,24 @@ public function getDownload($filename) */ private function getTemplate($template) { - $template = config("imagecache.templates.{$template}"); + $args = array(); + $data = config('imagecache.templates.'.$template); + + if(is_array($data)){ + $class = $data['class']; + $args = isset($data['args'])?$data['args']:array(); + }else{ + $class = $data; + } switch (true) { // closure template found - case is_callable($template): - return $template; + case is_callable($class): + return [$class, $args]; // filter template found - case class_exists($template): - return new $template; + case class_exists($class): + return [new $class, $args]; default: // template not found From 78fa466fdac6de55e256693f54896c59ffdbeef9 Mon Sep 17 00:00:00 2001 From: Arjan Kempes Date: Fri, 10 Mar 2017 15:01:31 +0100 Subject: [PATCH 2/2] Get template from route segments --- src/Intervention/Image/ImageCacheController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Intervention/Image/ImageCacheController.php b/src/Intervention/Image/ImageCacheController.php index a22fe59..d612c69 100644 --- a/src/Intervention/Image/ImageCacheController.php +++ b/src/Intervention/Image/ImageCacheController.php @@ -3,6 +3,7 @@ namespace Intervention\Image; use Closure; +use Illuminate\Http\Request; use Intervention\Image\ImageManager; use Illuminate\Routing\Controller as BaseController; use Illuminate\Http\Response as IlluminateResponse; @@ -18,8 +19,10 @@ class ImageCacheController extends BaseController * @param string $filename * @return Illuminate\Http\Response */ - public function getResponse($template, $filename) + public function getResponse(Request $request, $filename) { + $template = $request->segment(substr_count(config('imagecache.route'), '/')+2); + switch (strtolower($template)) { case 'original': return $this->getOriginal($filename);