php使用phpqrcode类库生成带图片LOGO的二维码

这段有个小项目要用到二维码生成,而且要求二维码中间带有一个LOGO图标,索性就查了些资料,发现有一个PHP类库phpqrcode对生成这种二维码很方便,下面把自己的用法和代码与大家分享,具体代码:


include ('phpqrcode.php');

$value = 'www.codesc.net';//二维码数据

$errorCorrectionLevel = 'L';//纠错级别:L、M、Q、H

$matrixPointSize = 10;//二维码点的大小: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二维码的文件名

?>

互联网+时代,时刻要保持学习,携手千锋PHP,Dream It Possible。

你可能感兴趣的:(php使用phpqrcode类库生成带图片LOGO的二维码)