欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-05-11 13:39:13
...
  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. ?>
复制代码