Laravel Response base64数据到图像

时间:2017-09-08 11:39:02

标签: laravel

我有base64编码的字符串格式的图像。 我想通过laravel中的URL返回图像 我使用了以下代码但没有工作

return response('data:image/png;base64,'.$logo)->header('Content-Type', 'image/png'); //not working 

return response($logo)->header('Content-Type', 'image/png');//not working

我不想要这样的图片:<img src="data:image/png;base64,'.$logo.'">因为图片需要在电子邮件正文中显示。

1 个答案:

答案 0 :(得分:0)

    $thumbData = explode(';base64,', $thumb);
    $imageType = str_replace('data:', '', $thumbData[0] ?? '');
    $thumbData = $thumbData[1] ?? '';
    $imageStream = base64_decode($thumbData);
    return \Response::stream(function() use($imageStream) {
        echo $imageStream;
    }, 200, ["Content-Type"=> $imageType]);