文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>图形随机码的生成。。

图形随机码的生成。。

时间:2006-09-29  来源:felixtong


效果:
CODE:
[Copy to clipboard]
php
$im = imagecreate(48, 25); //传回一个长为48,宽为25的空白图形
     
    $backgroundcolor = imagecolorallocate ($im, 255, 255, 255); //匹配颜色
    $black = imagecolorallocate($im,100,100,100); //同上
    $bordercolor = imagecolorallocate($im , 150, 150, 150); //同上
     
    //debug 增加图片的掺杂特性
    $linenums = mt_rand(10, 32); //在10-32间取个乱数
   //下面这个for循环是干嘛用的啊(画实线?)
    for($i=0; $i ++) {
        $linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
        $linex = mt_rand(0, 48);
        $liney = mt_rand(0, 25);
        imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor); //画一条实线
    }     
//在图上循环画64个点   
    for($i=0; $i ++) {
        $pointcolor = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50, 255));
        imagesetpixel($im, mt_rand(0, 48), mt_rand(0, 25), $pointcolor); //在图上画一点,坐标为(mt_rand(0, 48),mt_rand(0, 25))
    }
     
    $string = "";
      $arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','a','b');//把想要码的填进来
      srand((double) microtime()*10000000); //配置随机数种子
      $randcode = array_rand($arr,4); //从$arr中随机选4个数
      for($i=0;$i//生成4位随机数
      $string .= $arr[$randcode[$i]];
      }
     
    imagerectangle($im, 0, 0, 47, 24, $bordercolor); //在图片上画长方形
    imagestring($im,7,4,4,$string,$black);  //画横式字符串   
    //debug 合成图片
    header('Content-type: image/png');
    imagepng($im); //建立png图片
    imagedestroy($im); //释放空间
?>


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载