带有雪花背景 php验证码生成程序
Jun 08, 2016 pm 05:28 PM session_start();
$img_width=70; //先定义图片的长、宽
$img_height=28;
$num_array=range(0,9);
$small_char_array=range('a','z');
$big_char_array=range('A','Z');
$myarray=array_merge($num_array,$small_char_array,$big_char_array);
$mystring=$myarray[mt_rand(0,61)].$myarray[mt_rand(0,61)].$myarray[mt_rand(0,61)].$myarray[mt_rand(0,61)];
//exit($mystring);
//unset($_SESSION['shuzi']);
$_SESSION['shuzi'] = $mystring;
$aimg = imagecreate($img_width,$img_height); //生成图片
imagecolorallocate($aimg, 255,255,255); //图片底色,ImageColorAllocate第1次定义颜色PHP就认为是底色了
$black = imagecolorallocate($aimg,200,200,200); //定义需要的黑色
imagerectangle($aimg,0,0,$img_width-1,$img_height-1,$black);//先成一黑色的矩形把图片包围
//下面该生成雪花背景了,其实就是在图片上生成一些符号
for ($i=1; $i
imagestring($aimg,1,mt_rand(1,$img_width),mt_rand(1,$img_height),"*",imageColorAllocate($aimg,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255)));
//其实也不是雪花,就是生成*号而已。为了使它们看起来"杂乱无章、5颜6色",就得在1个1个生成它们的时候,让它们的位置、颜色,甚至大小都用随机数,rand()或mt_rand都可以完成。
}
//上面生成了背景,现在就该把已经生成的随机数放上来了。道理和上面差不多,随机数1个1个地放,同时让他们的位置、大小、颜色都用成随机数~~
//为了区别于背景,这里的颜色不超过200,上面的不小于200
imagestring($aimg,5,mt_rand(5,35),mt_rand(5,$img_height/2),$mystring,imageColorAllocate($aimg,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200)));
Header("Content-type: image/png"); //告诉浏览器,下面的数据是图片,而不要按文字显示
ImagePng($aimg); //生成png格式。。。嘿嘿效果蛮像回事的嘛。。。
ImageDestroy($aimg);

인기 기사

인기 기사

뜨거운 기사 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Windows 11에서 창 테두리 설정을 조정하는 방법: 색상 및 크기 변경

Windows 11에서 제목 표시줄 색상을 변경하는 방법은 무엇입니까?

Windows 11에서 작업 표시줄 축소판 미리 보기를 활성화 또는 비활성화하는 방법

golang에서 '정의되지 않음: rand.Seed' 오류를 해결하는 방법은 무엇입니까?
