Some time ago I wrote simple code in PHP to generate an image (captcha) and it works:
http://scr.hu/1yl7/9608b[/code:5pnrwpy8]
Today I again run code to make some documentation to improve it in future, but there is something weird...
Output image looks like this:
[code:5pnrwpy8]http://scr.hu/1yl7/63kgo[/code:5pnrwpy8]
and here is full code:
[code:5pnrwpy8]
<?php
function MakeRandomTxt($lenght = 5){
$characters = '!@#$%^&*()_+0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $lenght; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$rnd = MakeRandomTxt();
$string = $rnd;
$font_size = rand(24, 48);
$width = 140+imagefontwidth($font_size)*strlen($string);
$height = 36+imagefontheight($font_size);
$img = imagecreate($width,$height);
$bg = imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255));
$color = imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255));
$len = strlen($string);
$ypos = 14;
for($i=0;$i<$len;$i++){
$xpos = 64+$i * imagefontwidth($font_size);
imagechar($img, $font_size+20, $xpos, rand(2, $ypos), $string, $color);
$string = substr($string, 1);
}
header("Content-Type: image/png");
imagepng($img, './cp/'.$rnd.'.png');
imagedestroy($img);
?>
[/code:5pnrwpy8]
Pastebin version:
[code:5pnrwpy8]http://pastebin.com/wDvNYwDm[/code:5pnrwpy8]
What causing this problem?