0
私のすべての画像ソースにを使用したいと思います。Laravel-Glideをpublic/uploadsフォルダに使用
this instructionに続いて、http://myweb.dev/img/test.jpg?w=200&filt=sepia
で画像を取得できます。
ルート:
Route::get('/img/{path}', '[email protected]')->where('path', '.*');
コントローラー:
namespace App\Http\Controllers;
use Illuminate\Contracts\Filesystem\Filesystem;
use League\Glide\Responses\LaravelResponseFactory;
use League\Glide\ServerFactory;
class ImageController extends Controller
{
public function show(Filesystem $filesystem, $path)
{
$server = ServerFactory::create([
'response' => new LaravelResponseFactory(app('request')),
'source' => $filesystem->getDriver(),
'cache' => $filesystem->getDriver(),
'cache_path_prefix' => '.cache',
'base_url' => 'img',
]);
return $server->getImageResponse($path, request()->all());
}
}
すべての私のイメージは/公共/アップロードディレクトリなので、私は次のように変更しました。
ルート:私はhttp://myweb.dev/uploads/test.jpg?w=200&filt=sepiaに行くとき
Route::get('uploads/{path}', '[email protected]')->where('path', '.*');
コントローラ
public function show(Filesystem $filesystem, $path)
{
$server = ServerFactory::create([
'response' => new LaravelResponseFactory(app('request')),
'source' => public_path(),
'cache' => public_path(),
'cache_path_prefix' => '.cache',
'base_url' => 'uploads',
]);
return $server->getImageResponse($path, request()->all());
}
は、私はそのままの画像を取得するも、任意の.cacheディレクトリが作成されます。
base_path()
と/uploads
も試しましたが、どちらもうまくいきませんでした。私はelfinderのuploadsディレクトリを使用しています。
私はここで間違っていますか?