I am trying to make the profile view of user using image from byte array. I have successfully rendered the image, but I have problem including the image with other profile content, because of the header('Content-Type: image/png')
which takes the whole file as an image. How to resolve this problem?
$myArray = implode('', array_map(function($e) {
return pack("C*", $e);
}, $image));
if (substr($myArray, 0, 4) == "\x89PNG") header('Content-Type: image/png');
else if (substr($myArray, 0, 2) == "\xFF\xD8") header('Content-Type: image/jpeg');
else if (substr($myArray, 0, 4) == "GIF8") header('Content-Type: image/gif');
echo $myArray;
You can't serve raw image data as part of an HTML document.
There are a couple of ways you can go about serving the image:
#2 had the advantage of allowing the image to be cached by the browser. If the images are large I would try to work out a way to save it to a file.