I'm not sure about this but you can try.
$fileType = File::type($pathToImage);
$response = Response::make( File::get($pathToImage), 200);
$response->header("Content-Type", $fileType);
return $response;
I don't think you can pass the $img object directly, as it's an Intervention\Image object, not image data.
I think you can encode it however, before passing it to your response:
$img = Image::make('tmp/test.jpg');
return Response::make($img->encode('jpg'), 200, ['Content-Type' => 'image/jpeg']);
Good luck!
I had the same problem recently.. This works perfectly:
$img = Image::make('tmp/test.jpg');
return $img->response();
FYI, in Laravel 5, in your controlller:
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $path);
finfo_close($finfo);
// CSS files return incorrect mime type, so fix this
$path_parts = pathinfo($path);
if ($path_parts['extension'] == "css")
{
$mime = "text/css";
}
$response = response(file_get_contents($path), 200)->header('Content-Type', $mime);
return $response;
this works for me for images, html, js and css
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community