Friday, September 28, 2012

QR Code generation with PHP

Generating QR code with PHP is very easy. I had downloaded this library couple of days back..

Please download the class file BarcodeQR.php from http://www.shayanderson.com/


// Include the Library
include("BarcodeQR.php");

// Instantiate the BarcodeQR Object
$qr = new BarcodeQR();

// Info which will be put into the QR
$qr_text = "Account_no: 12345\nUsername: rocker\nEmail_address: test@gmail.com\nContact_no: 9988776655";

// Set object property
$qr->text($qr_text);

// Draw 
$qr->draw('206','254', "../path/to/your/QR_images/folder/test_qr.png");
?>

The above code is pretty self-explanatory. We need to include the class file, then create a object $qr with that class. Next we set the text which will be embedded in the QR image and finally we create the image using draw() method. The draw method takes Width, Height and Image path respectively.

Try it!! It's smooth and perfect.

1 comment:

Anonymous said...

Thanks for this. Really helpful for my small project. One question is, how can i handle user inputs then when a button clicked it will display the qr code? Thanks