php生成带背景图片的二维码
作者:星辰网络工作室 日期:2022-06-11 浏览:1740
//生成分享海报
public function createPoster(){
$uid = $this->uid;
$url = QR_CODE_DOMAIN."/wx_code/distribution?spread_uid=".$uid;
$file_pre = 'distribution_code_';//文件的前缀名
$qrcodename = ROOT_PATH."public/qrcode_tmp/".$file_pre.$uid.'.png';
vendor('phpqrcode.phpqrcode');
$cls = new \QRcode();
ob_clean();
$qr = $cls::png($url, $qrcodename, 'L', 2, 2);//写进临时目录
$back = ROOT_PATH."public/qrcode_tmp/123.png"; //背景图地址
//创建图片对象
$dst = imagecreatefromstring(file_get_contents(ROOT_PATH.'public'.$back));//背景图
$src = imagecreatefromstring(file_get_contents($qrcodename));//二维码
imagecopymerge($dst, $src, 50, 50, 0, 0,'72' ,'72', 90);
imagepng($dst,$qrcodename);
// exit;
if (file_exists($qrcodename)) {
echo $qrcodename;
} else {
echo '获取二维码失败';
}
}