Home  >  Article  >  Backend Development  >  PHP QRCode class library creates QR code with LOGO in the middle

PHP QRCode class library creates QR code with LOGO in the middle

WBOY
WBOYOriginal
2016-07-25 09:12:171145browse

Example, use the PHP QR Code class library to create a QR code.

1, browser output:

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

2, file output QR code

  1. include('phpqrcode/phpqrcode.php');
  2. // QR code data
  3. $data = 'http://bbs.it-home.org';
  4. // Generated file name
  5. $filename = '1111.png';
  6. // Error correction level: L, M, Q, H
  7. $errorCorrectionLevel = 'L';
  8. // Point size: 1 to 10
  9. $matrixPointSize = 4;
  10. QRcode: :png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
Copy code

3 to generate a QR code with logo in the middle

  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. $logo = imagecreatefromstring(file_get_contents($logo));
  12. $QR_width = imagesx($QR);
  13. $QR_height = imagesy($QR);
  14. $logo_width = imagesx($logo);
  15. $logo_height = imagesy($logo);
  16. $logo_qr_width = $QR_width / 5;
  17. $scale = $logo_width / $logo_qr_width;
  18. $logo_qr_height = $logo_height / $scale;
  19. $from_width = ( $QR_width - $logo_qr_width) / 2;
  20. imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
  21. }
  22. imagepng($QR,' xiangyanglog.png');
  23. ?>

Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn