Let's say I've done the following in PHP:
$image = imagecreatefromjpeg('myImage.jpg);
Is there a way the image data from $image could be converted to a string that could be sent in my AJAX response?
Let's say I've done the following in PHP:
$image = imagecreatefromjpeg('myImage.jpg);
Is there a way the image data from $image could be converted to a string that could be sent in my AJAX response?
Something like this should work to get a base64-encoded string from the image:
<?php
$image = imagecreatefromjpeg('myImage.jpg');
ob_start();
imagejpeg($image);
$imagestring = ob_get_contents();
ob_end_clean();
$encoded = base64_encode($imagestring);
?>
<pre><?php echo $encoded ?></pre>
<img src="data://image/jpeg;base64,<?php echo $encoded ?>" alt="myImage" />
This will output the base64-encoded image as a string and will also display the image using that encoded string.
Use base64, or some other binary->text encoding schemes available, and pass it with the data in ajax, and decode at the client.
PHP has base64 functions, see http://php.net/manual/en/function.base64-encode.php