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

来源:互联网 发布:淘宝店铺信誉度怎么刷 编辑:程序博客网 时间:2024/05/22 08:17

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

  1. <?php
  2. include ('phpqrcode.php');
  3. $value = 'www.codesc.net';//二维码数据
  4. $errorCorrectionLevel = 'L';//纠错级别:L、M、Q、H
  5. $matrixPointSize = 10;//二维码点的大小:1到10
  6. QRcode::png ( $value, 'ewm.png', $errorCorrectionLevel, $matrixPointSize, 2 );//不带Logo二维码的文件名
  7. echo "二维码已生成" . "<br />";
  8. $logo = 'emwlogo.gif';//需要显示在二维码中的Logo图像
  9. $QR = 'ewm.png';
  10. if ($logo !== FALSE) {
  11.     $QR = imagecreatefromstring ( file_get_contents ( $QR ) );
  12.     $logo = imagecreatefromstring ( file_get_contents ( $logo ) );
  13.     $QR_width = imagesx ( $QR );
  14.     $QR_height = imagesy ( $QR );
  15.     $logo_width = imagesx ( $logo );
  16.     $logo_height = imagesy ( $logo );
  17.     $logo_qr_width = $QR_width / 5;
  18.     $scale = $logo_width / $logo_qr_width;
  19.     $logo_qr_height = $logo_height / $scale;
  20.     $from_width = ($QR_width - $logo_qr_width) / 2;
  21.     imagecopyresampled ( $QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height );
  22. }
  23. imagepng ( $QR, 'ewmlogo.png' );//带Logo二维码的文件名

  1. ?>
 互联网+时代,时刻要保持学习,携手千锋PHP,Dream It Possible。 
原创粉丝点击