I'm trying to display a png image in PHP (Laravel)
So far I've tried
$response = Response::make(readfile(public_path() .
"/img/$image_name.png", 200))->header('Content-Type', 'image/png');
return $response;
and this
$file = public_path() . "/img/$image_name.png";
$im = imagecreatefrompng($file);
header('Content-Type: image/png');
imagePNG($im);
imagedestroy($im);
I always get something like this instead of an actual image
�PNG IHDR:�c PLTE����>tRNS�* �< pHYs���+uIDAT(�eұ� AJs *́[P��@8Ҍ��Y�:����s�A�"D�!B�"D�!B�"D�!C~����}��Q��N�+'��bP�.a&^O)%5Y\�L����.ޜ9��IEND�B`�
When I use jpeg header and jpeg image it starts showing the actual image in browser, but for some reason it doesn't work for png images. Have anyone faced a similar problem?
{{ asset("img/{$image_name}.png") }}. If you have a page with a lot of images on, serving them through PHP processes is going to create a lot of overhead.