Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP program to generate QR Code
#1
PHP Code:
<?php 
  
// Include the qrlib file 
include 'phpqrcode/qrlib.php'
  
// $text variable has data for QR  
$text "GEEKS FOR GEEKS"
  
// QR Code generation using png() 
// When this function has only the 
// text parameter it directly 
// outputs QR in the browser 
QRcode::png($text); 
?>


Note: This output is directly generated in the browser. This code will not run on an online IDE because it can’t include ‘phpqrcode’ module.

Example 2: PHP program to generate QR Code and create file.

PHP Code:
<?php 
// Include the qrlib file 
include 'phpqrcode/qrlib.php'; 
$text 
"GEEKS FOR GEEKS"; 
  
// $path variable store the location where to  
// store image and $file creates directory name 
// of the QR code file by using 'uniqid' 
// uniqid creates unique id based on microtime 
$path 'images/'; 
$file 
$path.uniqid().".png"; 
  
// $ecc stores error correction capability('L') 
$ecc 'L'; 
$pixel_Size 
10; 
$frame_Size 
10; 
  
// Generates QR Code and Stores it in directory given 
QRcode::png($text$file$ecc$pixel_Size$frame_Size); 
  
// Displaying the stored QR code from directory 
echo "<center><img src='".$file."'></center>"; 
?>
  

The output of both examples are different. In the first example, the output will display in default frame and pixel size which is generated directly on browser whereas the output of the second example is a ‘png’ file with pixel and frame size as 10 stored in a directory.
  


Bookmarks

Forum Jump:


Users browsing this thread:
1 Guest(s)