I have a PHP script that generates an image with PHP GD. After it generates the image, it saves it, and send this output when called by Ajax:
imagejpeg($img_data
You should modify the header before doing the echo $img_data;
echo $img_data;
header("Content-Type: image/jpeg"); header("Content-Length: " .sizeof($img_data));