PHP 生成二维码

下载phpqrcode.php
下载地址:http://files.cnblogs.com/files/qhorse/phpqrcode.rar

 1 <?php
 2 include 'phpqrcode.php';   
 3 $value = 'https://www.baidu.com/'; //二维码内容  
 4 $errorCorrectionLevel = 'L';//容错级别  
 5 $matrixPointSize = 6;//生成图片大小  
 6 //生成二维码图片  
 7 QRcode::png($value, 'qrcode.png', $errorCorrectionLevel, $matrixPointSize, 2);
 8  
 9 //以上生成内容是 https://www.baidu.com 的二维码图片
10 //如果需要给二维码加入logo,继续往下走
11  
12 $logo = 'logo.png';//准备好的logo图片  
13 $QR = 'qrcode.png';//已经生成的原始二维码图  
14  
15 if ($logo !== FALSE) {  
16     $QR = imagecreatefromstring(file_get_contents($QR));  
17     $logo = imagecreatefromstring(file_get_contents($logo));  
18     $QR_width = imagesx($QR);//二维码图片宽度  
19     $QR_height = imagesy($QR);//二维码图片高度  
20     $logo_width = imagesx($logo);//logo图片宽度  
21     $logo_height = imagesy($logo);//logo图片高度  
22     $logo_qr_width = $QR_width / 5;  
23     $scale = $logo_width/$logo_qr_width;  
24     $logo_qr_height = $logo_height/$scale;  
25     $from_width = ($QR_width - $logo_qr_width) / 2;  
26     //重新组合图片并调整大小  
27     imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,  
28     $logo_qr_height, $logo_width, $logo_height);  
29 }  
30 //输出图片  
31 imagepng($QR, 'weixin.png');  
32 echo '<img src="weixin.png">';

转载自:https://www.yuque.com/u30882/xb4115/gr8qvq
posted @ 2020-09-26 14:50  九鹤  阅读(69)  评论(0编辑  收藏  举报