0
所以我有一個奇怪的問題,使用Laravel內的GD庫。 我可以正確保存文件。 Base64_encode返回正確的圖像。 但我不能爲我的生活得到它在瀏覽器中顯示。 在我的我的TestController具備以下條件:GD庫 - 無法輸出到瀏覽器(Laravel)
<?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;
}
}
這只是返回一個破碎的形象。
控制檯顯示正確的標題。我拉我的頭髮...
其實我得到一個黑色的方塊與你的代碼..你可以給我們整個控制器的行動代碼? – zorx
這就是我正在尋找的。我正在使用預裝GD的Laravel的宅基地(4.0)。將更新代碼。 –
你不得不提到你正在使用laravel 4.0(因爲我在5.2上測試過) – zorx