• php生成二维码


    //https://sourceforge.net/projects/phpqrcode/files/   下载地址
    
    include 'phpqrcode/phpqrcode.php';
    
    class MyQrcode{
    
        /*
         * 普通生成二维码
         * @param string $url
         * @param int $size
         * @param string $output_path
         * @param string $filename
         * @return array
         */
        public function createNormal($url='',$size=4,$output_path='',$filename='')
        {
            if(empty($url))
            {
                return array('result'=>"fail",'msg'=>"url参数为空");
            }
    
            if(empty($path))
            {
                $output_path='./';
            }
    
            if(empty($filename))
            {
                $filename=md5(time()).'.png';
            }
    
            //容错级别
            $errorCorrenctionLevel = 'l';
    
            Qrcode::png($url,$output_path.$filename,$errorCorrenctionLevel,$size,2);
    
            return array('result'=>'success','msg'=>"生成成功",'imgurl'=>$output_path.$filename);
        }
    
        public function createHasCenterImage($url='',$centerImg='',$size=4,$output_path='',$output_filename='',$tempfile='temp.png')
        {
            if(empty($url))
            {
                return array('result'=>"fail",'msg'=>"url参数为空");
            }
    
            if(empty($path))
            {
                $output_path='./';
            }
    
            if(empty($output_filename))
            {
                $output_filename=md5(time()).'.png';
            }
            if(empty($centerImg))
            {
                return array('result'=>"fail",'msg'=>"中心图片参数为空");
            }
    
            if(!file_exists($centerImg))
            {
                return array('result'=>"fail",'msg'=>"中心图片不存在");
            }
    
    
    
            //容错级别
            $errorCorrenctionLevel = 'l';
    
            Qrcode::png($url,$tempfile,$errorCorrenctionLevel,$size,2);
    
            if(!file_exists($tempfile))
            {
                return array('result'=>"fail",'msg'=>"生成临时二维码失败");
            }
    
    
            $logo = $centerImg;
            $qrcode = $tempfile;
            $logo = imagecreatefromstring(file_get_contents($logo));
            $qrcode = imagecreatefromstring(file_get_contents($qrcode));
            $QR_width = imagesx($qrcode);//二维码图片宽度
            $QR_height = imagesy($qrcode);//二维码图片高度
            $logo_width = imagesx($logo);//logo图片宽度
            $logo_height = imagesy($logo);//logo图片高度
            $logo_qr_width = $QR_width / 5;
            $scale = $logo_width/$logo_qr_width;
            $logo_qr_height = $logo_height/$scale;
            $from_width = ($QR_width - $logo_qr_width) / 2;
    
            //重新组合图片并调整大小
            imagecopyresampled($qrcode, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,$logo_qr_height, $logo_width, $logo_height);
            //保存生成的二维码
            $r= imagepng($qrcode,$output_path.$output_filename);
    
    
            //删除临时的二维码图片
            @unlink($tempfile);
    
    
            if($r==true)
            {
                return array('result'=>"success",'msg'=>"生成二维码成功",'imgurl'=>$output_path.$output_filename);
            }
            else
            {
                return array('result'=>"fail",'msg'=>"生成二维码失败");
            }
        }
    }
    
    
    $obj=new MyQrcode();
    $obj->createNormal('http://www.baidu.com',4,'./'.'tt.png');
  • 相关阅读:
    [实变函数]4.4 依测度收敛
    [实变函数]4.3 可测函数的构造
    [实变函数]4.2 Egrov 定理
    [实变函数]4.1 可测函数 (measurable function) 及其性质
    [实变函数]4.0 引言
    [实变函数]3.3 可测集类
    垂直滚动选择效果的实现
    unity模型任意无限切割插件
    微信小程序—智能小蜜(基于智能语义解析olami开放平台)
    AdPlayBanner:功能丰富、一键式使用的图片轮播插件
  • 原文地址:https://www.cnblogs.com/norm/p/7286317.html
Copyright © 2020-2023  润新知