Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

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.

The generated QR code image can be returned as a string, served for download or returned as an URL string.

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

Back to method list

Method namelink($url)
DescriptionCreates QR code with provided link
Input parametersstring $url - url to endcode in QR code
Example inputlink("http://webcodingeasy.com")

QR code with bookmark

Back to method list

Method namebookmark($title, $url)
DescriptionCreates QR code with bookmark to provided link
Input parameters

string $title - title of bookmark

string $url - bookmark url

Example inputbookmark("Webcoding Easy", "http://webcodingeasy.com")

QR code with text

Back to method list

Method nametext($text)
DescriptionCreates QR code with provided text
Input parameters

string $text - text to encode in QR code

Example inputtext("Code snippets for PHP, Javascript. Ajax and mysql solutions, script implementations, security and optimization tips")

QR code with sms

Back to method list

Method namesms($phone, $text)
DescriptionCreates QR code with sms data
Input parameters

string $phone - phonenumber to whch to send sms

string $text - sms text

Example inputsms("123345678", "Code snippets for PHP, Javascript. Ajax and mysql solutions, script implementations, security and optimization tips")

QR code with phone number

Back to method list

Method namephone_number($phone)
DescriptionCreates QR code with phone number
Input parameters

string $phone - phonenumber to whch to send sms

Example inputphone_number("123345678")

QR code with Contact info

Back to method list

Method namecontact_info($name, $address, $phone, $email)
DescriptionCreates 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 inputcontact_info("Arturs Sosins", "Stadiona street 15", "123345678", "user@example.com")

QR code with email

Back to method list

Method nameemail($email, $subject, $message)
DescriptionCreates QR code with email
Input parameters

string $email - email address of person

string $subject - Email's subject

string $message - email text

Example inputemail("user@example.com", "Email subject", "Email text, text, text")

QR code with geographical location

Back to method list

Method namegeo($lat, $lon, $height)
DescriptionCreates QR code with geographical location
Input parameters

double $lat - latitude

double $lon - longitude

double $height - height from earth in meters

Example inputgeo(46.404723, -105.838165, 15)

QR code with wifi connection information

Back to method list

Method namewifi($type, $ssid, $pass)
DescriptionCreates 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 inputwifi("WEP", "home_network", "123456")

QR code with I-appli information

Back to method list

Method nameiappli($adf, $cmd, $param)
DescriptionCreates 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 inputiappli("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 namecontent($type, $size, $content)
DescriptionCreates 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 inputcontent("image/gif", "1385", "100100001110001...")

Get QR code image

Method nameget_image($size = 150, $EC_level = "L", $margin = "0")
DescriptionReturn 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:

  • L - [Default] Allows recovery of up to 7% data loss
  • M - Allows recovery of up to 15% data loss
  • Q - Allows recovery of up to 25% data loss
  • H - Allows recovery of up to 30% data loss

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 nameget_link($size = 150, $EC_level = "L", $margin = "0")
DescriptionReturn 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:

  • L - [Default] Allows recovery of up to 7% data loss
  • M - Allows recovery of up to 15% data loss
  • Q - Allows recovery of up to 25% data loss
  • H - Allows recovery of up to 30% data loss

int $margin - white margin around QR code

Example usageecho "<img src='".$qr->get_link()."' border="0"/>";

Forcing download dialog

Method namedownload_image($file)
DescriptionForce 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

Back to method list

Method namesave_image($file, $path)
DescriptionSave 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 inputsave_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

Like our script? Rate it at PHP > Hot Scripts

Scripts.com
RATE ME!

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

blog comments powered by Disqus