💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
~~~ 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 } ~~~