INTRODUCTION
This is a port of the QRcode image PHP scripts version 0.50g, by Y.Swetake (Japanese page). The code itself is pretty much untouched from his original version, I simply converted it into a CodeIgniter helper file. The zip file below contains all of the original read-me files as well as his original source file.
Note: this file is now hosted on my personal site: http://bobsawyer.com/files/qr_image_helper.zip
In a nutshell, these are 2D barcode images that can be read and interpreted by any one of several small applications you install on your mobile phone. The barcode can be a bit of text, a URL (in which case your smartphone will open the URL in your mobile browser), or can even send an SMS message.
Here’s a typical QRCode image. If you have a QRCode reader already installed on your phone, scanning the image below will take you to my company’s home page, http://www.pixelsandcode.net.
![]()
For more information on QRCode images and what you can do with them, check out http://semapedia.org/ and http://p8t.ch/ for some cool examples.
INSTRUCTIONS:
1. Download the .zip file below and open it.
2. Place the qr_img_helper.php file into your /system/helpers/ directory.
3. Put the /data and /image directories somewhere and make a note of their location. I suggest putting them in your /system/libraries/ directory.
SETTING UP THE CONFIGS
Either create a new config file for the qrcode configs or add them to
your existing config.php file.
/*
|--------------------------------------------------------------------------
| QR Image Config
|--------------------------------------------------------------------------
|
| $config['qrcode_data_path'] is the path to the /data directory
| $config['qrcode_image_path'] is the path to the /image directory
| $config['qrcode_save_path'] is the directory to save generated images into
|
| These paths should be full absolute directory paths.
| I have placed the /data and /image directories into the 'system/libraries'
| directory, but you should be able to put them anywhere setting the paths below.
|
| You must also make sure that the permissions on the 'qrcode_save_path'
| directory are set to 777 so that the server can create and save the images
| into that directory.
|
*/
$config['qrcode_data_path'] = '/path/to/your/home/system/libraries/data/';
$config['qrcode_image_path'] = '/path/to/your/home/system/libraries/image/';
$config['qrcode_save_path'] = '/path/to/your/home/images/qrs/';
SETTING UP THE CONTROLLER
In the controller that you’ll be using to generate the QRCode image, you’ll need to create an array to pass the data to the helper function:
$data = 'this is a test';
$filename = 'qrImage.jpg';
$qrdata = array(
'd' => $data,
'e' => 'M',
's' => 12,
'v' => 1,
't' => 'J',
'f' => $filename
);
The variables represented above are:
d = URL encoded data - whatever you want to encode into the image.
e = ECC level: L, M, Q, H (default M)
s = module size: 4-16 (default PNG:4, JPEG:8)
v = version: 1-40 or Auto (default: Auto)
t = image type: J = jpeg image, P = PNG image
In addition, there are structured append items m of n that are experimental:
n = structure append n (2-16)
m = structure append m (1-16)
p = parity
o = original data (URL encoded data) for calculating parity
Once your array is set, simply pass it to the qrencode() function:
$data = 'this is a test';
$filename = 'qrImage.jpg';
$qrdata = array(
'd' => $data,
'e' => 'M',
's' => 12,
'v' => 1,
't' => 'J',
'f' => $filename
);
qrencode($qrdata);
You can then reference the image as you normally would:
$path = $this->config->item('qrcode_save_path');
$data['qrimage'] = $path . $filename;
$this->load->view('yourpage',$data);
Which of course allows you to do this:
<img src="<?=$qrimage?>" alt="QRCode Image" />
GET THE FILE
Download the archive: http://bobsawyer.com/files/qr_image_helper.zip
VERSION HISTORY
Version 1.0: 03 December 2008
TECHNICAL SUPPORT
Bear in mind that I did not write the QRCode generator itself, I merely ported it to CI, and can only support it to that extent. In other words, if you have problems with the generator itself, please contact the original author. If you have problems setting up or using this helper within your CI project, I can probably help with that. For any questions or problems with this helper file, visit the official support forum thread and I’ll do my best to assist.
Cheers,
Bob
