//将四个数字随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$im = imagecreate(60,20)
$strx=rand(3,8);
for($i=0;$i<4;$i++){
$strpos=rand(1,6);
imagestring($im,5,$strx,$strpos, substr($num,$i,1), $black);
$strx+=rand(8,12);
} 上面的代码的$strx=rand(3,8);$strx+=rand(8,12);这两句不是很明白,这两句怎么将$im的60平分呢,还是这里根本不是平分,可以帮我解释一下这两句代码的意思吗?特别是$strx+=rand(8,12);这句,先谢谢了
$im = imagecreate(60,20)
$strx=rand(3,8);
for($i=0;$i<4;$i++){
$strpos=rand(1,6);
imagestring($im,5,$strx,$strpos, substr($num,$i,1), $black);
$strx+=rand(8,12);
} 上面的代码的$strx=rand(3,8);$strx+=rand(8,12);这两句不是很明白,这两句怎么将$im的60平分呢,还是这里根本不是平分,可以帮我解释一下这两句代码的意思吗?特别是$strx+=rand(8,12);这句,先谢谢了
$im = imagecreate(60,20);
$text = "hell"; // 验证码字符,四字节
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);$strx=rand(3,8);
for($i=0;$i<4;$i++){
$strpos=rand(1,6); // 这个是纵坐标y
imagestring($im,5,$strx,$strpos, substr($text,$i,1), $textcolor);
$strx+=rand(8,12);
}header("Content-type: image/png");
imagepng($im);$strx是横坐标,$strx+=rand(8,12); 得到的结果总是越来越大,这样每个字符间都会保持距离(距离多少随机,但一定会有 8>5)
横坐标最大也只能到44像素,加上字体大小5像素.(还要考虑非等宽字体,例如 l, w。但60应该足够)
for($i=0; $i<4; $i++) {
echo $strx += 12;//rand(8,12) 介于 8 到 12 之间,取最大值 12
echo '<br>';
}
20
32
44
56