1. 程式人生 > >phpqrcode生成二維碼的3種類型步驟

phpqrcode生成二維碼的3種類型步驟

<?php
// ==============php phpqrcode 生成二維碼======================== 
// 下載地址:http://sourceforge.net/projects/phpqrcode/files/latest/download 
// 只需要包含 phpqrcode.php 檔案就可以。 


// 一:直接輸出 
include "phpqrcode.php"; 
$value="http://www.top789.cn"; 
$errorCorrectionLevel = "L"; // 糾錯級別:L、M、Q、H 
$matrixPointSize = "4"; // 點的大小:1到10 
QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize); 




// 二:圖片檔案輸出 
include('phpqrcode.php'); 
$data = 'http://www.top789.cn'; 
$filename = 'test.png'; // 生成的檔名 
$errorCorrectionLevel = 'L'; // 糾錯級別:L、M、Q、H 
$matrixPointSize = 4; // 點的大小:1到10 
QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2); 




//三: 生成中間帶logo的二維碼 
include('phpqrcode.php'); 
$value='http://www.top789.cn'; 
$logo = 'logo.jpg'; // 中間的logo 
$QR = "moban.jpg"; // 自定義生成的。結束後可以刪除 
$last = "last.jpg"; // 最終生成的圖片 
$errorCorrectionLevel = 'L'; 
$matrixPointSize = 10; 
QRcode::png($value, $QR, $errorCorrectionLevel, $matrixPointSize, 2); 
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,$last); // 生成最終的檔案