php生成帶背景圖片的二維碼
作者:星辰網絡工作室 日期:2022-06-11 瀏覽:471
//生成分享海報
????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?'獲取二維碼失敗';
????????}
????}