当前位置:编程学习 > php >>

php随机图片效果

看到有人能够做到随机显示图片的效果,图片地址是一个PHP文件。

请问。。这个要通过什么方式做到呢。。(事先声明本人对这个PHP代码一窍不通。。)

然后。。帮忙下吧。。多谢。。

答案:function authImg() {//验证码生成
 srand((double)microtime()*1000000);//播下一个生成随机数字的种子,以方便下面随机数生成的使用
 //session_start();//将随机数存入session中
 $_SESSION['authnum']="";
 $im = imagecreate(60,20) or die("Cant's initialize new GD image stream!");   //制定图片背景大小
 $yellow = ImageColorAllocate($im, 255,102,0); //设定三种颜色
 $white = ImageColorAllocate($im, 255,255,255);
 $gray = ImageColorAllocate($im, 231,227,231);
 //imagefill($im,0,0,$gray); //采用区域填充法,设定(0,0)
 imagefill($im,0,0,$gray);//ed
 //生成数字和字母混合的验证码方法
 $ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
 $list=explode(",",$ychar);
 for($i=0;$i<4;$i++){
    $randnum=rand(0,35);
    $authnum.=$list[$randnum]." ";//ed 加入一个空格
 }
 //while(($authnum=rand()%100000)<10000); //生成随机的四位数
 //将四位整数验证码绘入图片
 $_SESSION['authnum']=$authnum;
 //int imagestring(resource image,int font,int x,int y,string s, int col)
 imagestring($im, 3, 5, 3, $authnum, $yellow);
 //用col颜色将字符串s画到image所代表的图像的x,y座标处(图像的左上角为0,0)。
 //如果 font 是 1,2,3,4 或 5,则使用内置字体

 for($i=0;$i<100;$i++){ //加入干扰象素 {
 $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
 // imagesetpixel($im, rand()%90 , rand()%30 , $randcolor);
 imagesetpixel($im, rand()%90 , rand()%30 , $white);
 }
 ImagePNG($im,"authimg.png");
 ImageDestroy($im);
 echo '<img src="authimg.png" width="60" height="20" />';
}

在这说不清楚  加偶QQ:793868474  上网时候偶教你  还可以教你搞亮QQ哦  放心 免费  希望采纳哦
其实很简单,你要做的就是给你的问题加上足够多的悬赏分,然后静静的等待,哈哈。

你只要加上足够的悬赏分然后静静的等待即可

验证码?如果是验证码  你网上一搜 php 验证码 多的是这样的代码

上一个:php关于静态化生成
下一个:Php链接数据问题

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,