• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php生成验证码,缩略图及水印图的类分享_php实例

php 搞代码 3年前 (2022-01-25) 20次浏览 已收录 0个评论

封装了一个类,可生成验证码,缩略图,及水印图,分享给大家

<?phpclass image{  session_start();  //验证码类  static public function verify($code,$width=75,$height=25,$n=4){    header("content-type:image/png");    // 创建画布    $img=imagecreatetruecolor($width,$height);    // 设置背景色    $bgcolor=imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),rand(200,255));    // 将背景色填充    imagefill($img,0,0,$bgcolor);    // 绘制五条弧线    for($i=0;$i<5;$i++){      $arccolor=imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),rand(200,255));      imagearc($img,mt_rand(5,($width-5)),mt_rand(5,($height-5)),mt_rand(5,($width-5)),mt_rand(5,($height-5)),mt_rand(0,360),mt_rand(0,360),$arccolor);    }    // 绘制一百个点    for($i=0;$i<100;$i++){      $pixelcolor=imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),rand(200,255));      imagesetpixel($img,mt_rand(1,($width-1)),mt_rand(1,($height-1)),$pixelcolor);    }    // 绘制五条线段    for($i=0;$i<5;$i++){      $linecolor=imagecolorallocate($img,mt_rand(200,255),mt_rand(200,255),rand(200,255));      imageline($img,mt_rand(1,($width-1)),mt_rand(1,($height-1)),mt_rand(1,<div>……本2文来源gaodai.ma#com搞##代!^码@网3</div><code>搞代gaodaima码</code>($width-1)),mt_rand(1,($height-1)),$linecolor);    }    // 设置边框颜色    $bdcolor=imagecolorallocate($img,mt_rand(150,200),mt_rand(150,200),rand(150,200));    // 绘制一个矩形无填充边框    imagerectangle($img,0,0,($width-1),($height-1),$bdcolor);    // 设置验证码字符串    $str='';    for($i=1;$i<=$n;$i++){      $str.=substr(str_shuffle($code),0,1);    }    $_SESSION['a']=$str;    //    for($i=0;$i

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php生成验证码,缩略图及水印图的类分享_php实例
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址