🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ composer require aferrandini/phpqrcode ~~~ ~~~ public function getOrderQrCodeAttr($value, $data) { $url = 'order/qr_code/'.date('Y-m-d',time()).'/'; $filename = $url.$data['order_id'].'.png'; // 二维码数据$code if (!file_exists($url)){ mkdir ($url,0777,true); } if (file_exists($filename)) { //已存在就不生成 // return '/'.$filename; } $code = $data['order_id']; // 生成的文件名 // 纠错级别:L、M、Q、H/容错级别 容错级别L(7%)、M(15%)、Q(25%)、H(30%) 容错级别越高 越容易扫描 $errorCorrectionLevel = 'H'; // 点的大小:1到10 $matrixPointSize = 6; QRcode::png($code, $filename, $errorCorrectionLevel, $matrixPointSize, 2); //二维码里面放logo $logo_url = 'img/share_page_logo.png'; if ($logo_url) { $QR = imagecreatefromstring(file_get_contents($filename)); $logo = imagecreatefromstring(file_get_contents($logo_url)); $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); //输出图片 imagepng($QR, $filename); //已经在本地生成 } return '/'.$filename; //返回base64 //$image_info = getimagesize($filename); //$base64_image_content = "data:{$image_info['mime']};base64," . //chunk_split(base64_encode(file_get_contents($filename))); //return $base64_image_content; //返回base64 } ~~~