个人从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); //销毁一图像
?>
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
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28