My server is running php and I want it to be able to send me images. For instance “profile.jpg”.
In C# i just populate a bitmap image with the source, but how do I create a source, a file that outputs the images binary data?
I have this:
<?php
$file = 'profil.jpg';
$image = imagecreatefromjpeg($file);
imagealphablending($image, false);
imagesavealpha($image, true);
// start buffering
ob_start();
imagepng($image);
$contents = ob_get_contents();
ob_end_clean();
echo "<img src='data:image/jpeg;base64,".base64_encode($contents)."' />";
imagedestroy($image);
?>
But it outputs HTML, could i just echo base64_encode($contents)?
I’d say you’re missing the headers and instead of cleaning the buffer you should flush it, something like that (off the top of my head)
Something like that. You can of course add more information or have less in the header, depending on what you need at the other end. HTTP/1.1: Header Field Definitions. Also Output Control Fctns