Im trying to get the generated image from PHP via ajax.
Q.1 When ajax renders PHP it shows some symbols not the picture which it shows when PHP is run alone. How to i get the image PHP outputs and not those symbols?
Q2. How do i change the font size of the text rendered into the image?
PHP.
$im = imagecreate(300, 20);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 5, 15, 1, '564545446', $black);
header ('Content-type: image/png');
imagepng($im, null, 3);
Ajax:
$.CaptchaLoad = function(){
$.ajax({
type:"POST",
complete: function(){
},
url:"../php/captcha.php"
}).done(function(feedback){
$('.CaptchaImg').html(feedback)
});
}
Answer #1:
<img id="capcha" src="../php/captcha.php" height="30" width="300"/>
your.CaptchaImg
container.Use reload handler for capcha load like this:
Useful link: Refresh image with a new one at the same url.
Answer #2:
You may use another parameters to change font size. For example add
GET
-parameter to image load script. Then capture it on server and react while you rendering capcha image.Client-side:
Server-side:
P.S.: Also, you have forgot to use
imagedestroy($im);
in the end of PHP script.