php实现生成带背景图片的二维码

2022-03-08 17:17:57 浏览数 (1)

场景

用户推广二维码链接传给后台生成带背景图片的二维码

实现代码
代码语言:javascript复制
public function getPromote()
	{
	    //生成推广二维码
	    $qrcode_path = './Public/attached/code/code'.'_'.$this->user['id'].'.png';
	    $content = C('SITE_URL').'/qrcoderegister?refer='.$this->user['int_code'];
	    if(!is_file($qrcode_path)){
	        $matrixPointSize = 10;
	        $matrixMarginSize = 1;
	        $errorCorrectionLevel = 'M';
	        makecode_no_pic($content,$qrcode_path,$matrixPointSize,$matrixMarginSize,$errorCorrectionLevel);
	    }
	    $this->res['data']['qrcode'] = C('URL').'/Public/attached/code/code'.'_'.$this->user['id'].'.png';
	    $this->res['data']['int_code'] = $this->user['int_code'];
	    $this->res['data']['url'] = $content;
	    $this->response($this->res,'json');
	}

makecode_no_pic方法:

代码语言:javascript复制
function makecode_no_pic($content,$qrcode_path_new,$matrixPointSize,$matrixMarginSize,$errorCorrectionLevel){
    ob_clean ();
    Vendor('phpqrcode.phpqrcode');
    $object = new QRcode();
    $object::png($content,$qrcode_path_new, $errorCorrectionLevel, $matrixPointSize, $matrixMarginSize);
}

0 人点赞