dsimib1625 2016-04-28 17:57
浏览 134

GD库 - 无法输出到浏览器(Laravel)

So I have a weird issue using the GD library inside Laravel. I can save the file correctly. Base64_encode returns the correct image. But I cant for the life of me get it to show in the browser. In my TestController I have the following:

<?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;
    }
}

That just returns a broken image.

The Console shows the correct headers. I'm pulling my hair out...

  • 写回答

1条回答 默认 最新

  • dras2334 2016-04-28 19:43
    关注

    So stupid. Found a space before the php tag in my package's config file. I really can't believe it was something so stupid.

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题