首页 > php教程 > PHP源码 > 正文

封装了一个类,可生成验证码,缩略图,及水印图

PHP中文网
发布: 2016-05-26 08:18:12
原创
1177人浏览过

php代码

<?php
class 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,($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
登录后复制

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号