0

I have image in base64 encoded string format. I want to return image through URL in laravel I used following code but not working

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

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

I don't want image like this: <img src="data:image/png;base64,'.$logo.'"> because image need to show in email body.

Sharad Kale
  • 971
  • 1
  • 7
  • 19

1 Answers1

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]);
dmitri
  • 460
  • 5
  • 11