Glide库 | 图片无法加载

9

我正在尝试将此库启用到我的本地环境。

http://glide.thephpleague.com/1.0/config/integrations/laravel/

Laravel当前版本为 5.5

gd2已在wamp扩展中启用。

我找不到问题出在哪里。

路径正确,图像已经存在其中。

请查看以下服务器配置代码:

$server = ServerFactory::create([
            'response' => new LaravelResponseFactory(app('request')),
            'source' => $source,
            //'cache' => new Filesystem(new Adapter('../storage/app/cache/')),
            'cache' => $cache,
            'cache_path_prefix' => '.cache',
            'base_url' => 'transform-img',
        ]);

现在我使用这个。
return $server->getImageResponse($path, request()->all());

它没有给出任何错误。

当我使用dd()时,我得到了这个响应。

StreamedResponse {#1151 ▼
  #callback: Closure {#1177 ▶}
  #streamed: false
  -headersSent: false
  +headers: ResponseHeaderBag {#1176 ▶}
  #content: null
  #version: "1.0"
  #statusCode: 200
  #statusText: "OK"
  #charset: null
}

回调闭包:


#callback: Closure {#1252 ▼
    class: "League\Glide\Responses\SymfonyResponseFactory"
    this: LaravelResponseFactory {#1231 …}
    use: {
      $stream: stream resource @543 
        timed_out: false
        blocked: true
        eof: false
        wrapper_type: "plainfile"
        stream_type: "STDIO"
        mode: "rb"
        unread_bytes: 0
        seekable: true
        uri: "D:\wamp\www\Bankrolla\storage\app/public\.cache/img/logo_no_text.png/32c8e67d979eab40a7ef6d1854f1f7cc"
        options: []
      }
    }
    file: "D:\wamp\www\Bankrolla\vendor\league\glide-symfony\src\Responses\SymfonyResponseFactory.php"
    line: "48 to 54"
  }

虽然statusCode显示为200,并且没有文件未找到的错误,但当我导航时它仍然不会加载任何图像,而是在浏览器上显示占位符。

可能出了什么问题?如果我尝试用任何其他随机字符串替换图像名称,则会收到有关找不到图像的错误。所以这意味着它确实找到了该图像。尽管无法呈现该图像。

我已经搜索过谷歌,并在他们的GitHub评论中搜索过,但找不到与我的问题类似的问题。

如果我直接加载它,我只会得到一个空白页面/图像。

enter image description here

我还查看了缓存目录,其中包括文件,这些文件的尺寸已调整大小。因此,即使生成缓存文件,我也不确定哪里出了问题。

enter image description here

也许我在这里漏掉了什么?

更新

$source变量的值:

Filesystem {#1225 ▼
  #adapter: Local {#1226 ▼
    #pathSeparator: "\"
    #permissionMap: array:2 [▼
      "file" => array:2 [▼
        "public" => 420
        "private" => 384
      ]
      "dir" => array:2 [▼
        "public" => 493
        "private" => 448
      ]
    ]
    #writeFlags: 2
    -linkHandling: 2
    #pathPrefix: "D:\wamp\www\Bankrolla\storage\app/public\"
  }
  #plugins: []
  #config: Config {#1229 ▼
    #settings: []
    #fallback: null
  }
}

我的公共目录中的存储目录(它是原始存储的符号链接)

在这里输入图片描述

Laravel 的存储目录

在这里输入图片描述

我从中调用此 URL。

{localhostDomainHere}/image/img/logo_no_text.png?w=100&h=100&fit=crop-center


@Bart 尝试了两个库。 不确定您所说的Web服务器缓存条目是什么意思,因为我的本地主机上没有启用缓存。 我正在本地主机上工作。 - Sizzling Code
@samo 添加了闭包。 - Sizzling Code
如果我想复制你的问题,我需要安装该软件包并上传一张图片,对吗?还有其他什么需要注意的吗? - syam
它在我的系统上运行得很好,你能在这里发布$source的值吗? - syam
你有任何想法吗?我也遇到了这个问题,但不知道该如何修复。很遗憾,一些图像显示了,而另一些则没有显示(空白页面)。 - Kelvin
显示剩余17条评论
2个回答

1

不知道你是否已经解决了这个问题。但是我们几天前遇到了同样的问题。经过长时间的搜索,我们发现错误是由配置文件中的一个新行引起的:

config file

所以,请检查所有配置文件的开头标签前是否有空格或换行符。否则,您的响应将不再是有效的响应,并且您将得到一个空框。

如果这不是配置文件,则需要检查在请求中加载的所有文件。

0

$source所提到的路径是放置图像的地方。如果它是1.jpg,那么调用url server_url/img/1.jpg。img来自您在问题中发布的函数的路由。在我的情况下,$source和$cache都是/storage/app,并将图像放在其中,并在该图像上调用路由。希望这可以帮助您。

请检查此内容

输入图像描述 这是我的代码:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Illuminate\Contracts\Filesystem\Filesystem;
use League\Glide\Responses\LaravelResponseFactory;
use League\Glide\ServerFactory;

class GlideController 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());
    }
}

路由:

Route::get('/img/{path}', 'GlideController@show')->where('path', '.*');

这是我的 storage/app 的内容

enter image description here


已经定义了如下路由。 Route::get('/transform-img/{path}', 'ImageController@show')->where('path', '.*'); - Sizzling Code
但是你正在调用这个"{localhostDomainHere}/image/img/logo_no_text.png?w=100&h=100&fit=crop-center"。你应该调用"{localhostDomainHere}/transform-img/img/logo_no_text.png?w=100&h=100&fit=crop-center"。 - syam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接