联系我们
  • 成才热线:
                0531-86996651  86996089
  • 地理位置:
                济南市山大路201号创展中心
                文化东路北100米
  • 乘车路线:
                16路、48路、K94路、112路
                文化东路站
  • PEAQQ群:
                39852963  25515397
  • 使用PHP生成校验图片
    发布时间:2007-09-13 07:02:25    作者:匆匆     类别:PHP技术    访问次数:642

    //将随机数存入session中
    session_start();
    $_SESSION['authnum']=substr(md5(time()),rand(0,25),5);
    //绘制图片
    Header("Content-type: image/PNG");
    $width = 100;
    $height = 40;
    $im = imagecreate($width,$height); //制定图片背景大小
    //第一次对 imagecolorallocate() 的调用会填充背景色
    $gray = ImageColorAllocate($im, 220,220,220); //背景为灰色
    $black = ImageColorAllocate($im, 0,0,0);
    //array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )
    imagettftext($im,20,-10,10,23,$black,'C:\WINDOWS\Fonts\arial.ttf',$_SESSION['authnum']);
    //加入干扰象素
    for($i=0;$i<100;$i++){
    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
    imagesetpixel($im, rand(0,$width) , rand(0,$height) , $randcolor);
    }
    imageline($im,rand(0,$width) , rand(0,$height) ,rand(0,$width) , rand(0,$height) ,$randcolor);
    //图片输出
    ImagePNG($im);
    ImageDestroy($im);
    ?>

     




    回复:

    请输入验证码: 点击重置图片