Rendering a blob image with PHP + Laravel

Asked

Viewed 385 times

1

My image is saved in the database. When I take it and give it a dd it returns which is a Resource stream, so I’m using the following code to get the content from it:

stream_get_contents($data['img'])

And it returns the Contents of this image in Base64, I believe, because it returns several letters and numbers together.

I wonder how I can render this image

  • Take a look here and here. I believe these answers can help you

  • or try it like this: &#xA;$contents = stream_get_contents($data['img']);&#xA;$base64 = 'data:image/PNG;base64,' . base64_encode($contents);&#xA;echo "<img src=$base64 />" ;

  • I tried something like= Return base64_decode(stream_get_contents($data['img'])); and appeared: PNG Ihdrrro& U1idatx 1 @ O B! ½ = K$ $K % DI"�$�X�H,I$�$K �%���DI" $ X H,I$ $K % DI"�$�X�H,I$�$K �%���DI" $ X H,I$ $K % DI"�$�X�H,I$�$K �%���DI" $ need to return without the <img> tag as I am creating an api

  • In case, will you recover this data via a link in the API Routes? This API will be consumed in PHP?

  • No. The api is in php, the image is in the database, I’m doing the api. I gave a select on the image and now I want to return to create a server link with this rendered image. A React application will consume my api

1 answer

1


I solved my problem using the Intervention Image library

 $img = Image::make(stream_get_contents($data['img']));
 return $img->response();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.