Laravel Glide在扩展名的网址上找不到图像

问题描述 投票:1回答:2

我正在使用Glide,并关注了这个视频https://vimeo.com/118089742,它基本上是在官方网站http://glide.thephpleague.com/上的说明。

这是我的服务提供商:

$this->app->singleton('League\Glide\Server', function ($app) {

        return \League\Glide\ServerFactory::create([
                'source' => public_path(),
                'cache' => public_path(),
                'source_path_prefix' => 'images/uploads',
                'cache_path_prefix' => 'images/cache',
                'base_url' => '/img/',
        ]);
    });

这是我目前的路线:

Route::get('img/{path}', function (League\Glide\Server $server, Illuminate\Http\Request $request) {
    $server->outputImage($request);
});

但我遇到了问题。当我去url.com/img/test.png?h=100时,它不起作用。当查看页面上的chrome dev工具时,我得到了图像的404(但是,原始图像会出现)。

我发现,如果我将路由切换到以下,并且只转到url.com/img/test?h=100(没有扩展名),那么我得到了我想要的Glided图像:

 Route::get('img/{path}', function (League\Glide\Server $server,  Illuminate\Http\Request $request) {
    $server->outputImage($request->path() . '.png', $request->all());
});

但是,如果我删除扩展的串联并简单地使用:

Route::get('img/{path}', function (League\Glide\Server $server,  Illuminate\Http\Request $request) {
    $server->outputImage($request->path(), $request->all());
});

然后返回url.com/img/test.png?h=100,它再次失败。

你看到我正在做什么有什么问题,或者有没有解释为什么我不能直接进入图像路径(带扩展名)?

laravel image-manipulation php-glide
2个回答
1
投票

我遇到了同样的问题并尝试了很多东西。所有以/ ing /开头的网址都是Glide生成的图片。所有in / assets /都是静态文件。我已经放弃并改变了

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$

location ~* ^/assets/.*\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$

希望有人有一个很好的解决方案!


0
投票

这都是一个缓存问题。在使用Glide之前,请不要通过htaccess或nginx缓存图像。

© www.soinside.com 2019 - 2024. All rights reserved.