![](/img/trans.png)
[英]How can I define a route in web.php to show 404 view in Laravel?
[英]define a Route to show images via timthumb php script in laravel
我希望有一個Route,它采用圖像Dimension和source,並通過timthumb php腳本返回Cropped和resized圖像。
我把timthumb.php文件放在公共目錄的一個文件夾中,我寫了這條路線:
Route::get('/showImage/{w}/{h}/{src}', function ($w , $h , $src) {
$img = 'public/plugins/timthumb/timthumb.php?src='.$src.'&w='.$w.'&h='.$h;
return Response::make($img, 200, array('Content-Type' => 'image/jpeg'));
})->where('src', '[A-Za-z0-9\/\.\-\_]+');
但什么都沒發生。
如何訪問timthumb.php文件並發送所需參數並獲取結果圖像?
更新:這是公共目錄的結構和timthumb和images文件夾的位置:
根據,我嘗試:
$img = 'public/plugins/timthumb/timthumb.php?src=../../'.$src.'&w='.$w.'&h='.$h;
而且:
$img = 'public/plugins/timthumb/timthumb.php?src=public/'.$src.'&w='.$w.'&h='.$h;
但它們都不適用於下面的URL:
http://localhost:8000/showImage/100/200/upload/slideshow/slide2.jpg
我建議使用league/glide
。 觀看在Laravel中使用Glide開始使用。
使用干預/圖像在Laravel中使用timthumb圖像的更好方法安裝此軟件包。
更新您的路線:
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\/\.\-\_]+');
或圖像緩存
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\/\.\-\_]+');
圖片網址如下:
http:// <<域名>> / showImage / 800/400 / Desert.jpg
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.