Wednesday, March 14, 2012

QR Code Generator

What is really amazing about QR Codes is that it is also a very impressive and powerful open source code – which means that you can have your own QR Code PHP that you can create and use. For people who deal very frequently with QR Codes, there will be absolutely no problems whatsoever in coming up with their own codes and using it but the issue of finding and creating a reader that can be used to decode the result would be a little bit of a problem. However, we have met some real talents who can come up with their own QR code using PHP programing. This would take an expert, so, beginners, you might want to stay out of this one.

Find QR Code library file


class qrcode
{
private $data;

//creating code with link mtadata
public function link($url){
if (preg_match('/^http:\/\//', $url) || preg_match('/^https:\/\//', $url))
{
$this->data = $url;
}
else
{
$this->data = "http://".$url;
}
}

//creating code with bookmark metadata
public function bookmark($title, $url){
$this->data = "MEBKM:TITLE:".$title.";URL:".$url.";;";
}

//creating text qr code
public function text($text){
$this->data = $text;
}

//creatng code with sms metadata
public function sms($phone, $text){
$this->data = "SMSTO:".$phone.":".$text;
}

//creating code with phone
public function phone_number($phone){
$this->data = "TEL:".$phone;
}

//creating code with mecard metadata
public function contact_info($name, $address, $phone, $email){
$this->data = "MECARD:N:".$name.";ADR:".$address.";TEL:".$phone.";EMAIL:".$email.";;";
}

//creating code wth email metadata
public function email($email, $subject, $message){
$this->data = "MATMSG:TO:".$email.";SUB:".$subject.";BODY:".$message.";;";
}

//creating code with geo location metadata
public function geo($lat, $lon, $height){
$this->data = "GEO:".$lat.",".$lon.",".$height;
}

//creating code with wifi configuration metadata
public function wifi($type, $ssid, $pass){
$this->data = "WIFI:T:".$type.";S:".$ssid.";P:".$pass.";;";
}

//creating code with i-appli activating meta data
public function iappli($adf, $cmd, $param){
$param_str = "";
foreach($param as $val)
{
$param_str .= "PARAM:".$val["name"].",".$val["value"].";";
}
$this->data = "LAPL:ADFURL:".$adf.";CMD:".$cmd.";".$param_str.";";
}

//creating code with gif or jpg image, or smf or MFi of ToruCa files as content
public function content($type, $size, $content){
$this->data = "CNTS:TYPE:".$type.";LNG:".$size.";BODY:".$content.";;";
}

//getting image
public function get_image($size = 150, $EC_level = 'L', $margin = '0'){
$ch = curl_init();
$this->data = urlencode($this->data);
curl_setopt($ch, CURLOPT_URL, 'http://chart.apis.google.com/chart');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);

$response = curl_exec($ch);
curl_close($ch);
return $response;
}

//getting link for image
public function get_link($size = 150, $EC_level = 'L', $margin = '0'){
$this->data = urlencode($this->data);
return 'http://chart.apis.google.com/chart?chs='.$size.'x'.$size.'&cht=qr&chld='.$EC_level.'|'.$margin.'&chl='.$this->data;
}

//forcing image download
public function download_image($file){
header('Content-Disposition: attachment; filename=QRcode.png');
header('Content-Type: image/png');
echo $file;
}

//save image to server
public function save_image($file, $path = "./QRcode.png"){
file_put_contents($path, $file);
}
}
?>
example.php
include("qrcode.php");
$qr = new qrcode();
$qr->text("BTP295298");

?>

If you want to download Click Here :)

No comments:

Post a Comment