首页 > 教程
PHP简易汉字验证码
- 2025-04-07
- 1256 ℃
<?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基本简单实用函数
相关内容
mysql数据库优化
3个DeepSeek隐藏玩法,99...
微信公众号支付(JSAPI)...
微信的8个实用功能,隐藏技巧
网页上传图片需要旋转的问题
为什么我国没有ChatGPT那...
使用电脑一定要学会的20...
网页HTML特殊字符编码对照表
-
Ant Design Vue 4.0 a-modal弹窗组件封装
2025-04-07 1140
-
微信商户号申请
2024-05-13 1673
-
Langchain 教程-文档检索
2025-05-06 1346
-
如何访问有密码的电脑
2025-06-21 1377
-
php批量去除文件bom代码
2024-03-16 1224
-
国内可用的AI大模型工具大合集
2024-03-16 1911
-
免费搭建最强网文神器网页版!完爆任何小说APP
2025-04-27 1123
-
微信快速把图片变成表格
2025-06-22 1474
-
如果你也想做公众号挣钱
2025-03-10 1234
-
免费下载PPT模板的网站来了
2025-03-10 1574
文章评论 (0)
- 这篇文章还没有收到评论,赶紧来抢沙发吧~


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