php随机图片效果
- 提问者网友:堕落的邪教徒
- 2021-02-12 17:21
- 二级知识专家网友:瘾与深巷
- 2021-02-12 17:53
$arr=array("图片地址1.jpg","图片地址2.jpg","图片地址3.jpg","图片地址4.jpg");
$a=rand(0,count($arr)-1);
header("Content-type: image/jpeg");
echo $arr[$a];
?>
如果你的php和图片在一个目录,并且图片都是有规律的 你要可以
$r=rand(1,10); //定义随机数字1到10
$pic=$r.".jpg"; //生成随机3.jpg类似地址 当然你也可以生成1a.jpg 只要 改.jpg 为a.jpg 就可以
header("Content-type: image/jpeg");
echo $pic;
?>
- 1楼网友:悲观垃圾
- 2021-02-12 18:51
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时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |