define a Route to show images via timthumb php script in laravel define a Route to show images via timthumb php script in laravel laravel laravel

define a Route to show images via timthumb php script in laravel


The better way to use timthumb image in Laravel using intervention/imageInstall this package.

Update your Route:

Route::get('showImage/{w}/{h}/{src}', function ($w , $h , $src) {    $img_path = public_path().'/'.$src;    $img = Image::make($img_path)->resize($w, $h);    return $img->response('jpg');})->where('src', '[A-Za-z0-9\/\.\-\_]+');

OR Image Cache

Install intervention/imagecache package

Route::get('showImage/{w}/{h}/{src}', function ($w , $h , $src)     {        $img_path = public_path().'/'.$src;        $img =  Image::cache(function($image)use($w,$h,$img_path) {                return $image->make($img_path)->resize($w, $h);            });        return Response::make($img, 200, ['Content-Type' => 'image/jpeg']);    })->where('src', '[A-Za-z0-9\/\.\-\_]+');

Image URL would be as below:

http://<< Domain Name >>/showImage/800/400/Desert.jpg