php 生成带图片的二维码

先生成二维码 

/**
 * host 生成链接地址
 * level 容错级别
 * size 图片大小
 */
function qrcode($url='storeID=1',$level=3,$size=8){

    Vendor('phpqrcode.phpqrcode');

    $errorCorrectionLevel =intval($level) ;//容错级别
    $matrixPointSize = intval($size);//生成图片大小
    //生成二维码图片
    $object = new QRcode();
    ob_end_clean();
    $filename = 'qrcode/'.time().rand(1000, 9999).'.png';
    $object->png($url, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
    return $filename;
}

在生成带图片的二维码

/**
 * 生成带logo的二维码
 */
function logo_qrcode($qrcode, $logo = './php.jpg')
{
    $qr = $qrcode;
    if ($logo !== FALSE) { 
        $qrcode = imagecreatefromstring(file_get_contents($qrcode));
        $logo = imagecreatefromstring(file_get_contents($logo)); 
        $qrcode_width = imagesx($qrcode);//二维码图片宽度 
        $qrcode_height = imagesy($qrcode);//二维码图片高度 
        $logo_width = imagesx($logo);//logo图片宽度 
        $logo_height = imagesy($logo);//logo图片高度 
        $logo_qr_width = $qrcode_width / 5; 
        $scale = $logo_width/$logo_qr_width; 
        $logo_qr_height = $logo_height/$scale; 
        $from_width = ($qrcode_width - $logo_qr_width) / 2; 
        //重新组合图片并调整大小 
        imagecopyresampled($qrcode, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, 
        $logo_qr_height, $logo_width, $logo_height); 
    }
    imagepng($qrcode, $qr);
    return $qrcode;
}
原文地址:https://www.cnblogs.com/zjj1990/p/8980330.html