這段有個(gè)小項(xiàng)目要用到二維碼生成憨栽,而且要求二維碼中間帶有一個(gè)LOGO圖標(biāo)凹嘲,索性就查了些資料戳粒,發(fā)現(xiàn)有一個(gè)PHP類庫phpqrcode對生成這種二維碼很方便役首,下面把自己的用法和代碼與大家分享,具體代碼:
include?('phpqrcode.php');
$value?=?'www.codesc.net';//二維碼數(shù)據(jù)
$errorCorrectionLevel?=?'L';//糾錯級別:L掺逼、M吃媒、Q、H
$matrixPointSize?=?10;//二維碼點(diǎn)的大新来:1到10
QRcode::png?(?$value,?'ewm.png',?$errorCorrectionLevel,?$matrixPointSize,?2?);//不帶Logo二維碼的文件名
echo?"二維碼已生成"?.?"
";
$logo?=?'emwlogo.gif';//需要顯示在二維碼中的Logo圖像
$QR?=?'ewm.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,?'ewmlogo.png'?);//帶Logo二維碼的文件名
?>
互聯(lián)網(wǎng)+時(shí)代赘那,時(shí)刻要保持學(xué)習(xí),攜手千鋒PHP,Dream?It?Possible氯质。