如何用PHP生成扭曲和旋转的验证代码

如何用PHP生成扭曲和旋转的验证代码
复制代码代码如下所示:
< PHP
功能make_rand($长度= 32){ / /验证码文本生成函数
$str =abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz1234567890 ;
$结果;
($ i = 0;$ i $ $长度;$ + +){
Num { } =美元美元我兰德(0,61);
结果;
}
返回$结果;
}
$码= make_rand(5);
im_x = 160美元;
im_y = 32美元;
功能make_crand($长度=5){
$=;
($ i = 0;$ i $ $长度;$ + +){
为字符串= CHR(RAND(0xb0,0xf7)(。CHR)兰德(0xa1,0xfe));
}
返回$字符串;
}
功能getauthimage(文本im_x = 230美元,美元,美元im_y = 32){
$我=新建一个真彩色图像(im_x美元,美元im_y);
text_c美元= imagecolorallocate(合我,mt_rand(0100),mt_rand(0100),mt_rand(0100));
tmpc0美元= mt_rand(100255);
tmpc1美元= mt_rand(100255);
(100255)mt_rand TmPc2*美元=;
buttum_c美元= imagecolorallocate(合我,tmpc0美元美元美元,tmpc1,TmPc2*);
imagefill(合我,16, 13,buttum_c美元);
返回文本;
美元: / 字体= c /窗/ / / /字体是TTC的;
/ /回声strlen($文本);
为文本= iconv(GB2312
/ /回声mb_strlen(合文本,UTF-8);
为($我= 0;$我< mb_strlen($文本);$我+ +)
{
TMP = mb_substr美元(美元1美元的文字,我,,UTF-8);
$array =阵列(-1,0,1);
P = array_rand(数组);
美元=数组{ $ P } * mt_rand(9); / /角
美元= 20;
(我imagettftext美元,美元,10美元的规模,我* * + $美元2,25大小,text_c美元美元美元,字体,TMP);
}
distortion_im美元=新建一个真彩色图像(im_x美元,美元im_y);
imagefill(distortion_im美元,16, 13美元,buttum_c);
为($我= 0;美元美元美元我<< im_x;i++){
(J = 0;对美元美元美元,<< im_y;j++){
RGB = imagecolorat美元(美元美元美元我,I,J);
如果((int)($我+ 20 + sin(J / $ im_y×2×m_pi)* 10)= 0){
imagesetpixel(distortion_im美元,(int)($我+ 10 + sin(J / $ im_y×2×m_pi-m_pi×0.5)×3美元美元),J,RGB);
}
}
}
添加干扰像素;
$ = 600;干扰像素的数量
($ i = 0;$ i <计数;$ + +){
randcolor = imagecolorallocate美元(美元distortion_im,mt_rand(0255),mt_rand(0255),mt_rand(0255));
imagesetpixel(distortion_im美元,mt_rand()%()% mt_rand im_x美元,美元,美元im_y,randcolor);
}
line_c = 5美元;
/ / imageline
为($我= 0;美元美元美元我<< line_c;i++){
颜色= imagecolorallocate美元(美元distortion_im,17, 158, 20);
左撇子= mt_rand美元(1美元im_x-1);
好的mt_rand美元=(1,im_y-1美元);
imageline(distortion_im美元,0美元,左撇子,imagesx(distortion_im美元美元美元),右手的,颜色);
}
页眉(内容类型:图像);
以PNG格式输出到浏览器或文件中;
/ / imagepng(为我);
imagepng($ distortion_im);
/ /销毁一图像,结合图像的内存释放;
销毁一图像($ distortion_im);
销毁一图像(为我);
}
>

示例如下:
复制代码代码如下所示:
< PHP
getauthimage(make_crand(5));
>

tag:验证如何用代码电脑软件php

相关内容