Laravel 4.2干预图像显示破损图像


Laravel 4.2 Intervention-image displays broken image

我正在学习Laracast教程,了解如何使用Intervention处理图像操作。在将它添加到我的composer文件并运行composer更新后,我按照安装指南中的说明将其添加到服务提供商和别名中。此外,我正在使用Vagrant 1.7.4和一个名为Scotch box 2.5的Laravel虚拟盒子。

然而,我还没能在我的应用程序中成功使用Intervention。这是我的样本路线:

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">

不返回Response::make,只需执行以下操作:

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

你也可以这样做:

return $image->response();

默认情况下,响应数据将按照当前图像的类型进行编码。若还并没有定义图像类型,方法将返回jpeg编码的数据。

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