+ -
当前位置:首页 → 问答吧 → 个人从QEE 和 TP 的代码中提出来的 验证码 函数,使用方便

个人从QEE 和 TP 的代码中提出来的 验证码 函数,使用方便

时间:2010-09-11

来源:互联网

<?php
header("Content-type: image/gif");
$height=20;
$width=65;
$img = imagecreatetruecolor($width, $height);
$text_color = imagecolorallocate($img, 255,255,255); //设置字的颜色 http://www.wahart.com.hk/rgb.htm
$back_color = imagecolorallocate($img, 255,0,179); //设置背景颜色
imagefill($img, 0, 0, $back_color); //填充背景颜色
//添加杂色
    $point_color = imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
    for($i=0;$i<5;$i++){
        imagearc($img,mt_rand(-10,$width),mt_rand(-10,$height),mt_rand(30,300),mt_rand(20,200),55,44,$point_color);
    }
    for($i=0;$i<40;$i++){
        imagesetpixel($img,mt_rand(0,$width),mt_rand(0,$height),$point_color);
    }
    imagefilledrectangle($img, 33, 0, 65, 20, $point_color);//右侧添加一个矩形
//添加杂色
imagestring($img, 5, 15, 1,  "asdf", $text_color);    //水平地画一行字符串
    /*bool imagestring ( resource $image, int $font, int $x, int $y, string $s, int $col )
    imagestring() 用 col 颜色将字符串 s 画到 image 所代表的图像的 x,y 坐标处(这是字符串左上角坐标,整幅图像的左上角为 0,0)。
    如果 font 是 1,2,3,4 或 5,则使用内置字体。
    */
imagegif($img);        //以 JPEG 格式将图像输出到浏览器或文件 相应的还有imagepng、imagegif
imagedestroy($img);    //销毁一图像
?>

作者: duyongguang   发布时间: 2010-09-11

TP上的代码要比这个复杂的多啊!

作者: lbc227540   发布时间: 2010-09-11

相关阅读 更多