Purchase here and earn points Buy Exclusive Apps & Scripts

QR Code Generator with Google Chart API

QR code (abbreviated from Quick Response code) is the trademark for a type of matrix barcode (or two-dimensional barcode) first designed in 1994 for the automotive industry in Japan. A barcode is a machine-readable optical label that contains information about the item to which it is attached. In practice, QR codes often contain data for a locator, identifier, or tracker that points to a website or application. A QR code uses four standardized encoding modes (numeric, alphanumeric, byte/binary, and kanji) to store data efficiently; extensions may also be used.

The Quick Response system became popular outside the automotive industry due to its fast readability and greater storage capacity compared to standard UPC barcodes. Applications include product tracking, item identification, time tracking, document management, and general marketing.

A QR code consists of black squares arranged in a square grid on a white background, which can be read by an imaging device such as a camera, and processed using Reed–Solomon error correction until the image can be appropriately interpreted. The required data is then extracted from patterns that are present in both horizontal and vertical components of the QR Code image.

This is a PHP QR code generator class that helps to generate QR code image (PNG) or save QR code image as PNG file.

QR_Generator_by_jkdesignslk.php file.

class QR_BarCode{
private $googleChartAPI = 'http://chart.apis.google.com/chart';
private $codeData;

public function url($url = null){
$this->codeData = preg_match("#^https?\:\/\/#", $url) ? $url : "http://{$url}";

public function text($text){
$this->codeData = $text;

public function email($email = null, $subject = null, $message = null) {
$this->codeData = "MATMSG:TO:{$email};SUB:{$subject};BODY:{$message};;";

public function phone($phone){
$this->codeData = "TEL:{$phone}";

public function sms($phone = null, $msg = null) {
$this->codeData = "SMSTO:{$phone}:{$msg}";

public function contact($name = null, $address = null, $phone = null, $email = null) {
$this->codeData = "MECARD:N:{$name};ADR:{$address};TEL:{$phone};EMAIL:{$email};;";

public function content($type = null, $size = null, $content = null) {
$this->codeData = "CNTS:TYPE:{$type};LNG:{$size};BODY:{$content};;";

public function qrCode($size = 200, $filename = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->googleChartAPI);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "chs={$size}x{$size}&cht=qr&chl=" . urlencode($this->codeData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$img = curl_exec($ch);


if($img) {
if($filename) {
if(!preg_match("#\.png$#i", $filename)) {
$filename .= ".png";

return file_put_contents($filename, $img);
} else {
header("Content-type: image/png");
print $img;
return true;
return false;

To create QR code PNG image on your webpage, use index.php file like the following.


include "QR_Generator_by_jkdesignslk.php";

$qr = new QR_BarCode();




The above example code will generate and display QR code like on your webpage.


More options you can use:


$qr->email('emailAddress', 'subject', 'message');


$qr->sms('phoneNumber', 'message');

$qr->contact('name', 'address', 'phone', 'email');

$qr->content('type', 'size', 'content');


The QR Code class makes QR code creation quicker and easier. Only one file (QR_Generator_by_jkdesignslk.php) need to be included to generate different types of QR code. The cURL is used in QR_Generator_by_jkdesignslk.php class, make sure cURL is enabled in PHP.

Please download the file for more details...

We will be happy to hear your thoughts

Leave a reply

Select your currency
USD United States (US) dollar
Reset Password