Maison  >  Article  >  développement back-end  >  php结合phpqrcode生成带图片LOGO的二维码

php结合phpqrcode生成带图片LOGO的二维码

WBOY
WBOYoriginal
2016-08-08 09:21:49937parcourir

 PHP生成带LOGO的二维码,或许很多高手都已经实现了,但之前并没有过多关注这方面,这段有个小项目要用到二维码生成,索引就查了些资料,发些有一个PHP 类库phpqrcode对生成这种二维码很方便,索引就测试了一下,下面把自己的用法和代码与菜鸟分享,希望高手鼓励哦。

生成效果:中间带Logo图片

首先你需要下载这个类库包,或者我后边会附上这个类库,具体的使用代码:

1、基本的二维码生成单元,直接输出标准二维码:

<?php //文件输出    
    include(&#39;phpqrcode.php&#39;);    
// 二维码数据    
    $data = &#39;http://www.codesc.net&#39;;    
// 生成的文件名    
   $filename = &#39;ewm.png&#39;;   
// 纠错级别:L、M、Q、H    
    $errorCorrectionLevel = &#39;L&#39;;    
// 点的大小:1到10    
    $matrixPointSize = 4;    
    QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);    
?> 

2、生成标准二维码和带Logo的二维码:

<?php include (&#39;phpqrcode.php&#39;);
$value = &#39;http://www.codesc.net&#39;;//二维码数据
$errorCorrectionLevel = &#39;L&#39;;//纠错级别:L、M、Q、H
$matrixPointSize = 10;//二维码点的大小:1到10
QRcode::png ( $value, &#39;ewm.png&#39;, $errorCorrectionLevel, $matrixPointSize, 2 );//生成不带Logo的二维码图片文件名
echo "二维码已生成" . "<br />";
$logo = 'emwlogo.gif';//需要显示在二维码中的Logo图像
$QR = 'ewmlogo.png';//生成带Logo的二维码文件名
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' );
?>

版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了php结合phpqrcode生成带图片LOGO的二维码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn