I am learning to use JQuery and PHP. I simply want to display a text and an PHP generated image on a browser at a specific interval.
HTML Page:
<html>
<head>
<title>Testing PHP</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function() {
loadPHP();
});
function loadPHP() {
$("#PHP_data").load("loadPHP.php");
setTimeout(loadPHP, 2000);
}
//-->
</script>
</head>
<body>
<div id="PHP_data"></div>
</body>
</html>
loadPHP page
<?php
$rannum = mt_rand(1,100);
echo $rannum;
$thick = 10;
// create a 200*200 image
$img = imagecreatetruecolor(200, 200);
// Add antialias
imageantialias ($img, true);
// allocate some colors
$white = imagecolorallocate($img, 255, 255, 255);
// draw the dashed circle
for($t = 1;$t<($thick+1);$t++) {
for($i = 0;$i<360;$i+=10) {
imagearc($img, 100, 100, 200-($t/5), 200-($t/5), $i, $i+5, $white);
imagearc($img, 100, 100, 200+($t/5), 200+($t/5), $i, $i+5, $white);
}
}
// output image in the browser
header("Content-type: image/png");
imagepng($img);
// free memory
imagedestroy($img);
?>
When I call up the HTML Page I get this:
The Random number seems to be working fine. I do see it changing every two seconds, but the image is all screwed up. All I see is binary characters. Is this because you can only return image from PHP and absolutely no TEXT along with the image? How can I fix this?