PHP generates QR code example code

WBOY
Release: 2016-07-25 09:12:15
Original
1215 people have browsed it

What is QR code? QR code is a type of two-dimensional barcode that can compile information such as website addresses, text, photos, etc. into a square barcode pattern through corresponding encoding algorithms. Mobile phone users can re-decode the relevant information and view the content through the camera and decoding software. # Two sentences explanation: # If you include qrlib.php, you need to put it together with other files: files and folders. #phpqrcode.php is the merged version, you only need to include this file, but the generated image is slow and inaccurate # Two usages are given below:

  1. include('./phpqrcode/phpqrcode.php');
  2. // QR code data
  3. $data = 'http://bbs.it-home.org';
  4. // Generated file name
  5. $filename = $errorCorrectionLevel.'|'.$matrixPointSize.'.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);
  11. ?>
  12. # Create a QR code file
  13. QRcode: :png('code data text', 'filename.png');
  14. // creates file
  15. # Generates images to the browser
  16. QRcode::png('some othertext 1234');
  17. // creates code image and outputs it directly into browser
Copy the code

If you need to generate colorful ones, you need to do it yourself Modify the color setting part of the code in the image method of the QRimage class in phpqrcode.php. The 1.1.4 version of the code is on lines 987 and 988, with one foreground color and one background color:

  1. $col[0] = ImageColorAllocate($base_image,255,255,255);
  2. $col[1] = ImageColorAllocate($base_image,0,0,0);
Copy code

About QRcode For usage, you can also refer to the article: php generates QR code library (QRCode method), php generates QR code image class QRcode

2. Generate using google open api

  1. $urlToEncode="http://bbs.it-home.org";
  2. generateQRfromGoogle($urlToEncode);
  3. function generateQRfromGoogle($chl,$widhtHeight ='150',$ EC_level='L',$margin='0')
  4. {
  5. $url = urlencode($url);
  6. echo 'QR code';
  7. }
Copy code

For the method of google api to generate QR code, you can also refer to: php calls google interface to generate QR code QR code example, how to generate QR code using Google API

Address: http://phpqrcode.sourceforge.net/ Download: http://sourceforge.net/projects/phpqrcode/ 3.libqrencode Address: http://fukuchi.org/works/qrencode/index.en.html For php support, please refer to: http://hirokawa.netflowers.jp/entry/4900/

4.QRcode Perl CGI & PHP scripts Address: http://www.swetake.com/qr/qr_cgi.html



Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template