I am developing a web application. In my application, I need to work with some images and display it on the browser. But I am not saving the image as a file and access the file from the path. I am not doing it for some reason. Instead, I am creating an image resource from some kind of byte data and then serving it.
This is my code in the controller.
function serveS3Image(Request $request)
{
$image_data = Storage::disk('s3')->get($request->get('identifier'));
$data = imagecreatefromstring($image_data);
header('Content-Type: image/png');
imagepng($data);
}
When I access the action from the browser, it is displaying me correct image. But I want to do it in more Laravel way. Something like this:
function serveS3Image()
{
return Response::ImageResource($data);
}
How can I return the PHP image resource?