2017-01-05 10 views
0

私のすべての画像ソースに​​を使用したいと思います。Laravel-Glideをpublic/uploadsフォルダに使用

this instructionに続いて、http://myweb.dev/img/test.jpg?w=200&filt=sepiaで画像を取得できます。

enter image description here

ルート:

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ディレクトリを使用しています。

私はここで間違っていますか?

enter image description here

答えて

0

これが働いていました。 public/uploadsディレクトリに画像を置いています。

ルート

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' => public_path('uploads'), 
      'cache' => public_path('uploads'), 
      'cache_path_prefix' => '.cache', 
      'base_url' => 'img', 
     ]); 

     return $server->getImageResponse($path, request()->all()); 
    } 
} 
関連する問題