当前位置:Gxlcms > PHP教程 > PHPQRCode类库创建中间带LOGO的二维码

PHPQRCode类库创建中间带LOGO的二维码

时间:2021-07-01 10:21:17 帮助过:13人阅读

例子,使用PHP QR Code类库创建二维码。

1,浏览器输出:

  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. ?>

2,文件输出二维码

  1. include('phpqrcode/phpqrcode.php');
  2. // 二维码数据
  3. $data = 'http://bbs.it-home.org';
  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);

3,生成中间带logo的二维码

  1. include('phpqrcode/phpqrcode.php');

  2. $value='http://bbs.it-home.org';
  3. $errorCorrectionLevel = 'L';
  4. $matrixPointSize = 6;
  5. QRcode::png($value, 'xiangyang.png', $errorCorrectionLevel, $matrixPointSize, 2);
  6. echo "QR code generated"."
    ";
  7. $logo = 'logo.png';
  8. $QR = 'xiangyang.png';

  9. if($logo !== FALSE)

  10. {

  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,'xiangyanglog.png');
  24. ?>

人气教程排行