This commit is contained in:
2017-10-11 13:38:22 +02:00
4 changed files with 78 additions and 8 deletions

View File

@@ -4,14 +4,21 @@ namespace Meoran\Images\Http\Controllers;
use Closure;
use Illuminate\Http\Request;
use Intervention\Image\Constraint;
use Intervention\Image\Exception\ImageException;
use Intervention\Image\Exception\NotSupportedException;
use Laravel\Lumen\Routing\Controller as BaseController;
use Meoran\Images\Model\Image;
use Meoran\Images\Templates\Custom;
use ReflectionFunction;
use ReflectionMethod;
class ImagesController extends BaseController
{
public function get($filename, $template = null)
public function get($filename)
{
$template = app('request')->input('template');
if ($template === null) {
$template = 'original';
}
@@ -91,7 +98,10 @@ class ImagesController extends BaseController
return $template($image->make($path));
} else {
// build from filter template
return $image->make($path)->filter($template);
$res = $image->make($path)->filter($template);
if ($res === null) {
abort(404);
}
}
}
@@ -101,9 +111,10 @@ class ImagesController extends BaseController
* @param string $template
* @return mixed
*/
private function getTemplate($template)
private function getTemplate($templateName)
{
$template = config("images.templates.{$template}");
$template = config("image.templates.{$templateName}");
switch (true) {
// closure template found
case is_callable($template):
@@ -114,9 +125,8 @@ class ImagesController extends BaseController
return new $template;
default:
// template not found
abort(404);
break;
return $this->getCustomTemplate($templateName);
}
}
@@ -132,4 +142,11 @@ class ImagesController extends BaseController
'Etag' => md5($content)
));
}
private function getCustomTemplate($templateName)
{
$custom = new Custom();
$custom->actions = [$templateName];
return $custom;
}
}