【问题标题】:Laravel 4.2 Intervention-image displays broken imageLaravel 4.2 Intervention-image 显示损坏的图像
【发布时间】:2015-11-06 05:51:16
【问题描述】:

我正在按照 Laracast 教程使用干预处理 image manipulation。将其添加到我的作曲家文件并运行作曲家更新后,我按照installation guide 中的说明将其添加到我的服务提供者和别名中。另外,我正在使用 Vagrant 1.7.4 和一个名为 Scotch Box 2.5 的 Laravel 虚拟盒子。

但是,我无法在我的应用中成功使用干预。这是我的示例路线:

Route::get('foo', function() {
    $image = Image::make('http://placehold.it/500x500/000/e8117f');
    return Response::make($image->encode('jpg'), 200, ['Content-Type' => 'image/jpeg']);
});

当我在浏览器中访问该页面时,我看到的只是一个损坏的图像图标。我真的很困惑为什么 Chrome 中的开发人员检查器工具会显示:

<img style="-webkit-user-select: none" src="http://192.168.33.10/public/foo">

【问题讨论】:

    标签: php image laravel vagrant intervention


    【解决方案1】:

    您可以这样做,而不是返回Response::make

    return $image->response('jpg');
    

    您也可以这样做:

    return $image->response();
    

    默认情况下,响应数据将被编码为当前图像的类型。如果尚未定义图像类型,则方法将返回 jpeg 编码数据。

    来源:http://image.intervention.io/api/response

    【讨论】:

    • 我尝试了这些建议,但使用损坏的图像得到了相同的结果。
    • 很奇怪...你知道你是否满足系统要求吗? PHP >= 5.4,fileinfo 扩展,以及 GD 库 (>= 2.0) 或 Imagick PHP 扩展 (>=6.5.7)?
    • 嗯,根据虚拟框的creator,应该是使用PHP 5.6,GD和Imagick。
    猜你喜欢
    • 1970-01-01
    • 2017-12-08
    • 2010-12-14
    • 2013-09-13
    • 1970-01-01
    • 2017-06-23
    • 2020-12-05
    • 2018-05-05
    • 1970-01-01
    相关资源
    最近更新 更多