生成图片二维码
生成圖片二維碼,話不多說直接上代碼
<?phperror_reporting(E_ERROR);require_once 'phpqrcode/phpqrcode.php'; //引入生成圖片的文件$value='http://www.baidu.com'; //生成二維碼掃碼后訪問的頁面$errorCorrectionLevel = 'L'; $matrixPointSize = 10;? QRcode::png($value, './img/xiangyang.png', $errorCorrectionLevel, $matrixPointSize, 2,true); echo "QR code generated"."<br />"; $logo = './img/logo.png'; $QR = './img/xiangyang.png'; if($logo !== FALSE) { $QR = imagecreatefromstring(file_get_contents($QR)); $logo = imagecreatefromstring(file_get_contents($logo)); $QR_width = imagesx($QR); $QR_height = imagesy($QR); $logo_width = imagesx($logo); $logo_height = imagesy($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,'./img/xiangyanglog.png'); ?> png方法是生成二維碼,各個參數的意思如下:
$value:生成二維碼后掃碼時訪問的頁面
./img/xiangyang.png:生成的二維碼的路徑及二維碼圖片的名稱
$errorCorrectionLevel表示容錯率,也就是有被覆蓋的區域還能識別,分別是 L(QR_ECLEVEL_L,7%),M(QR_ECLEVEL_M,15%),Q(QR_ECLEVEL_Q,25%),H(QR_ECLEVEL_H,30%);
$matrixPointSize?:生成二維碼圖片的大小
2:表示二維碼周圍邊框空白區域間距值是2
true:表示保存二維碼并顯示,如果是false的話表示保存二維碼不顯示
?imagepng方法是生成中間帶固定圖片的二維碼各參數的意思如下:
$QR:中間的圖片
./img/xiangyanglog.png:生成的二維碼的路徑及二維碼圖片的名稱
總結
- 上一篇: 如何快速通过信息系统管理工程师考试
- 下一篇: java api 操作helm