Laravel 4.2干预 - 图像显示破碎的图像

时间:2015-11-05 21:33:35

标签: php image laravel vagrant intervention

我正在使用Laracast教程来处理image manipulation使用干预。将其添加到我的composer文件并运行composer update后,我按照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">

1 个答案:

答案 0 :(得分:0)

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

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

你也可以这样做:

return $image->response();
  

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

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

相关问题