title: Serving PHP image resource as response in Laravel
body: <p>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. </p>
  
  <p>This is my code in the controller.</p>
  
  <pre><code>function serveS3Image(Request $request)
  {
      $image_data = Storage::disk('s3')-&gt;get($request-&gt;get('identifier'));
      $data = imagecreatefromstring($image_data);
      header('Content-Type: image/png');
      imagepng($data);
  }
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>function serveS3Image()
  {
       return Response::ImageResource($data);
  }
  </code></pre>
  
  <p>How can I return the PHP image resource?</p>