首页 >后端开发 >php教程 >php生成二维码的类库(QRCode方法)

php生成二维码的类库(QRCode方法)

WBOY
WBOY原创
2016-07-25 08:57:181266浏览
  1. include "phpqrcode/phpqrcode.php";
  2. $value="http://bbs.it-home.org";
  3. $errorCorrectionLevel = "L";
  4. $matrixPointSize = "4";
  5. QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize);
  6. exit;
  7. ?>
复制代码

文件输出二维码:

  1. include('phpqrcode/phpqrcode.php');
  2. // 二维码数据
  3. $data = 'http://s.bookphone.cn';
  4. // 生成的文件名
  5. $filename = '1111.png';
  6. // 纠错级别:L、M、Q、H
  7. $errorCorrectionLevel = 'L';
  8. // 点的大小:1到10
  9. $matrixPointSize = 4;
  10. QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
  11. ?>
复制代码

生成中间带logo的二维码:

  1. //带中间logo的二维码

  2. //by bbs.it-home.org
  3. include('phpqrcode/phpqrcode.php');
  4. $value='http://bbs.it-home.org';
  5. $errorCorrectionLevel = 'L';
  6. $matrixPointSize = 6;
  7. QRcode::png($value, 'jbxue.png', $errorCorrectionLevel, $matrixPointSize, 2);
  8. echo "QR code generated"."
    ";
  9. $logo = 'logo.png';
  10. $QR = 'jbxue.png';
  11. if($logo !== FALSE)

  12. {
  13. $QR = imagecreatefromstring(file_get_contents($QR));

  14. $logo = imagecreatefromstring(file_get_contents($logo));
  15. $QR_width = imagesx($QR);
  16. $QR_height = imagesy($QR);
  17. $logo_width = imagesx($logo);
  18. $logo_height = imagesy($logo);
  19. $logo_qr_width = $QR_width / 5;
  20. $scale = $logo_width / $logo_qr_width;
  21. $logo_qr_height = $logo_height / $scale;
  22. $from_width = ($QR_width - $logo_qr_width) / 2;
  23. imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
  24. }
  25. imagepng($QR,'jbxue_log.png');
  26. ?>
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn