首页 > 教程
PHP简易汉字验证码
- 2025-04-07
- 1292 ℃
<?php
/**
* PHP实现简易汉字验证码的思路
*/
// 创建画布
$image = imagecreatetruecolor(200, 60);
$background = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $background);
// 画干扰点
for ($i=0; $i < 300; $i++) {
$pixColor = imagecolorallocate($image, rand(150, 240), rand(150, 240), rand(150, 240));
$pixX = rand(10, 190);
$pixY = rand(5, 55);
imagesetpixel($image, $pixX, $pixY, $pixColor);
}
// 画干扰线
//4条水平线
for ($i=0; $i < 5; $i++) {
$lineColor = imagecolorallocate($image, rand(50, 150), rand(50, 150), rand(50, 150));
$lineX1 = 0;
$lineX2 = 300;
$lineY1 = ($i + 1) * 12;
$lineY2 = ($i + 1) * 12;
imageline($image, $lineX1, $lineY1, $lineX2, $lineY2, $lineColor);
}
//10条垂直线
for ($i=0; $i < 30; $i++) {
$lineColor = imagecolorallocate($image, rand(50, 150), rand(50, 150), rand(50, 150));
$lineX1 = ($i + 1) * 10;
$lineX2 = ($i + 1) * 10;
$lineY1 = 0;
$lineY2 = 60;
imageline($image, $lineX1, $lineY1, $lineX2, $lineY2, $lineColor);
}
// 画汉字
$text = array('栀', '子', '花', '开');
for ($i=0; $i < 4; $i++) {
$textColor = imagecolorallocate($image, rand(20, 100), rand(20, 100), rand(20, 100));
$textX = $i * 50 + 10;
$textY = rand(40, 60);
// 字体文件为英文名
imagettftext($image, 30, rand(20, 50), $textX, $textY, $textColor, "STFANGSO.TTF", $text[$i]);
}
// 输出图像
header("content-type:image/png");
imagepng($image);
// 销毁图像
imagedestroy($image);
上一篇:微信小程序自用Tree树形控件
下一篇:PHP基本简单实用函数
相关内容
如何学习麻省理工学院课程
推荐39个让你效率提高200...
DeepSeek小白使用指南,9...
Vue底层判断标签的性能优...
怎么复制网站(禁止鼠标右...
微信文件传输助手不够用...
2025年8款免费且好用的图...
为什么当年历史课中西方...
-
3个DeepSeek隐藏玩法,99%的人都不知道
2025-04-30 1202
-
DeepSeek小白使用指南,99% 的人都不知道的使用技巧
2025-04-30 1319
-
大学可以不用买学校订的教材
2024-11-18 1844
-
JS正则常用校验大全
2025-04-07 1209
-
易支付对接微信商户完整流程
2024-02-06 4617
-
Vue3 + Vite + Vue Router 4后端返回路由配置动态路由权限管理
2025-04-07 1287
-
推荐7款免费好用的国内外服务器传输工具
2025-03-04 2041
-
Duplicate Cleaner Pro 重复文件查找清理工具
2021-07-16 1526
-
很上档次别具一格的代码注释方式
2025-04-07 1400
-
Excel文件比较器
2025-04-08 1519
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


进入有缘空间
点击分享文章