QR code generator class
Here is a QR code generator class in PHP that can be used to generate QR Code images using Google Chart API.
It can send an HTTP request to the Google Chart API Web server to request the generation of a PNG image that represents the QR code graphic for a given information snippet.
Currently the class can request the generation of QR codes for information snippets of types: bookmark, text, SMS message, phone number, contact information, e-mail message, geo-location, WIFI access, i-appli metadata or abitrary content-type.
QR-codes.co.cc is an example website using this class
Contents
Download
Example codes
<?php include("qrcode.php"); $qr = new qrcode(); //link $qr->link("http://webcodingeasy.com"); echo "<p>Link</p>"; echo "<p><img src='".$qr->get_link()."' border='0'/></p>"; //text $qr->text("Any UTF8 characters like Ä?ēū"); echo "<p>UTF8 text</p>"; echo "<p><img src='".$qr->get_link()."' border='0'/></p>"; //sms //First parameter - phone number //Second parameter - sms text $qr->sms("12345678", "sms text"); echo "<p>SMS with phone number and text</p>"; echo "<p><img src='".$qr->get_link()."' border='0'/></p>"; ?>
Examples in action
Example scripts provided with package in action:
Method list
- QR code with link
- QR code with bookmark
- QR code with text
- QR code with sms
- QR code with phone number
- QR code with Contact info
- QR code with email
- QR code with geographical location
- QR code with wifi connection information
- QR code with I-appli information
- QR code with file as content
- Get QR code image
- Get link to QR code image
- Forcing download dialog
- Saving image on server
QR code with link
| Method name | link($url) |
| Description | Creates QR code with provided link |
| Input parameters | string $url - url to endcode in QR code |
| Example input | link("http://webcodingeasy.com") |
QR code with bookmark
| Method name | bookmark($title, $url) |
| Description | Creates QR code with bookmark to provided link |
| Input parameters | string $title - title of bookmark string $url - bookmark url |
| Example input | bookmark("Webcoding Easy", "http://webcodingeasy.com") |
QR code with text
| Method name | text($text) |
| Description | Creates QR code with provided text |
| Input parameters | string $text - text to encode in QR code |
| Example input | text("Code snippets for PHP, Javascript. Ajax and mysql solutions, script implementations, security and optimization tips") |
QR code with sms
| Method name | sms($phone, $text) |
| Description | Creates QR code with sms data |
| Input parameters | string $phone - phonenumber to whch to send sms string $text - sms text |
| Example input | sms("123345678", "Code snippets for PHP, Javascript. Ajax and mysql solutions, script implementations, security and optimization tips") |
QR code with phone number
| Method name | phone_number($phone) |
| Description | Creates QR code with phone number |
| Input parameters | string $phone - phonenumber to whch to send sms |
| Example input | phone_number("123345678") |
QR code with Contact info
| Method name | contact_info($name, $address, $phone, $email) |
| Description | Creates QR code with contact info |
| Input parameters | string $name - name of person string $address - Person's address string $phone - phonenumber to whch to send sms string $email - person's email address |
| Example input | contact_info("Arturs Sosins", "Stadiona street 15", "123345678", "user@example.com") |
QR code with email
| Method name | email($email, $subject, $message) |
| Description | Creates QR code with email |
| Input parameters | string $email - email address of person string $subject - Email's subject string $message - email text |
| Example input | email("user@example.com", "Email subject", "Email text, text, text") |
QR code with geographical location
| Method name | geo($lat, $lon, $height) |
| Description | Creates QR code with geographical location |
| Input parameters | double $lat - latitude double $lon - longitude double $height - height from earth in meters |
| Example input | geo(46.404723, -105.838165, 15) |
QR code with wifi connection information
| Method name | wifi($type, $ssid, $pass) |
| Description | Creates QR code with wifi connection information like name of network, password, authentication type (supported by Android devices). |
| Input parameters | string $type - Authentication type like WAP or WPA string $ssid - name of network to connec to string $pass - password for network |
| Example input | wifi("WEP", "home_network", "123456") |
QR code with I-appli information
| Method name | iappli($adf, $cmd, $param) |
| Description | Creates QR code with i appli information to automatically start iappli application. i-appli aplication needs to be downloaded beforehand |
| Input parameters | string $adf - URL accessed to acquire the ADF of i-appli to be activated string $cmd - CMD command, the designated boot command must be declared within the AllowPushBy key of the ADF beforehand string $param - array with up to 16 parameter pairs array("name" => "somename", "value" => "somevalue") sent to the i-appli to be activated |
| Example input | iappli("http://www.nttdocomo.co.jp/test_appli.jam", "abcde", array(array("name" => "name1", "value" => "value1"),array("name" => "name2", "value" => "value2")) |
QR code with file as content
| Method name | content($type, $size, $content) |
| Description | Creates QR code with file as content like gif, jpg or midi files |
| Input parameters | string $type - type of files, currently supported file types are (image/gif, image/jpeg, application/x-mld, audio/midi, audio/mid, application/x-toruca) int $size - total file size in bytes string $content - file content data in binary code format |
| Example input | content("image/gif", "1385", "100100001110001...") |
Get QR code image
| Method name | get_image($size = 150, $EC_level = "L", $margin = "0") |
| Description | Return QR code image in png format |
| Input parameters | int $size - as image is always square, there is only one value for height and width in pixels string $EC_level - Error correction level:
int $margin - white margin around QR code |
| Example usage | header("Content-type: image/png"); echo $qr->get_image(); |
Get link to QR code image
| Method name | get_link($size = 150, $EC_level = "L", $margin = "0") |
| Description | Return link to QR code image in png format unsing Google Chart API |
| Input parameters | int $size - as image is always square, there is only one value for height and width in pixels string $EC_level - Error correction level:
int $margin - white margin around QR code |
| Example usage | echo "<img src='".$qr->get_link()."' border="0"/>"; |
Forcing download dialog
| Method name | download_image($file) |
| Description | Force to open image download dialog on client side to download image |
| Input parameters | int $file - image file from get_image method |
| Example usage | $file = $qr->get_image(); $qr->download_image($file); |
Saving image on server
| Method name | save_image($file, $path) |
| Description | Save generated image on the server |
| Input parameters | string $file - QR code image returned by get_image method string $path - path and file name where to save image |
| Example input | save_image($image, "./images/qr_code.png") |
Latest changes
- 15. February 2012 -
- fixed force download method
- added save_image method to save image on the server
- fixed Android wifi acces qrcode
- fixed existing example and additional example added
Rate us
Try it out and Rate on PHPclasses.org
Support
PHP classes support forum or comments below
You may also be interested in:
Powered by BlogAlike.com










