首页 > PHP > PHP基于phpqrcode.php生成二维码

PHP基于phpqrcode.php生成二维码

时间:2022-06-30浏览次数:536

PHP:

/** 
 *       L-默认:可以识别已损失的7%的数据 
 *       M-可以识别已损失15%的数据 
 *       Q-可以识别已损失25%的数据 
 *       H-可以识别已损失30%的数据 
 */ 
public function creatCode(){
    Vendor('phpqrcode');
    $recode=new \QRcode();

    $value='网址'   //二维码内容 
    $errorCorrectionLevel = 'M';//容错级别
    $matrixPointSize = 15;//生成图片大小
    //生成二维码图片
    $recode::png($value, './Public/images/defaultqrcode.png', $errorCorrectionLevel, $matrixPointSize, 1);            //已经生成的原始二维码图
    //$logo = C('CODE_LOGO');
    $logo = '';     //准备好的logo图片

    $QR = './Public/images/defaultqrcode.png';     //已经生成的原始二维码图

    if ($logo !== FALSE) {
        $QR = imagecreatefromstring(file_get_contents($QR));
        $logo = imagecreatefromstring(file_get_contents($logo));
        $QR_width = imagesx($QR);//二维码图片宽度
        $QR_height = imagesy($QR);//二维码图片高度
        $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($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,
            $logo_qr_height, $logo_width, $logo_height);
    }
    //输出图片
    ob_clean ();
    Header("Content-type: image/png");
    ImagePng($QR);
}


HTML:

<img src="{:U('Site/creatCode')}" style="width: 200px" />


phpqrcode.php 文件下载:

链接:https://pan.baidu.com/s/10tiKgInySIwTwhwEt7gZZw 

提取码:lnb4