GD库-Can';t输出到浏览器(Laravel)


GD Library - Can't output to browser (Laravel)

所以我在Laravel中使用GD库时遇到了一个奇怪的问题。我可以正确保存文件。Base64_encode返回正确的图像。但我一辈子都无法在浏览器中显示它。在我的TestController中,我有以下内容:

<?php
namespace App'Http'Controllers;
use App;
use Response;
class TestController extends Controller
{
    public function index()
    {
      $test = imagecreatetruecolor(300, 300);
      $background = imagecolorallocate($test, 0, 0, 0);
      imagefill($test, 0, 0, $background);
      ob_start();
      imagepng($test);
      $buffer = ob_get_contents();
      imagedestroy($test);
      ob_end_clean();
      $response = Response::make($buffer);
      $response->header('Content-Type', 'image/png');
      return $response;
    }
}

这只会返回一个破碎的图像。

控制台显示正确的标题。我要拔头发了。。。

太愚蠢了。在我的包的配置文件中,在php标记之前找到了一个空格。我真不敢相信这是如此愚蠢的事情。