Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
QR codes - graphics images that provide quick phone links

You'll have seen these printed "QR" codes turning up on printed documents such as railway timetables, brochures and business cards, and they allow you to wave your phone at the pattern and have a copy of the document (or other details) come up there in electronic form.

How do they work?

QR codes are really two dimensional barcodes. Hidden within the code is the text of a URL. QR code reader applications analyse the image, use the common features of the squares at three of the corners to work out its orientation and perspective, and then call up a browser of other application to take the user to the URL specified.

QR codes vary in size depending on the length of the data they're storing, and they hold a number of checking elements (you can choose how many / what strength) to ensure a correct interpretation of fuzzy or slightly damaged images.


How are they set up?

There are quite a few web sites that you can type a URL into and will give you a QR code. There isn't a central registry / look up for the codes, so you don't have to look for a good central supplier who you know you'll be able to trust, nor do you need to pay a fee.

Be aware, though, that QR codes can contain any URL, and you may find sites that return you an impure QR code - i.e. one that points to a URL on their server which they then redirect to you. Such redirects are very commonly used (and to great advantage and openly) on media such as Twitter, where http://bit.ly/z6oqQK is far fewer characters that http://www.wwrug.org.uk/calendar.html. These short codes together with QR mean a simpler and smaller matrix, but if you use them you are relying on the services of the people at bit.ly and the survival of their service for the duration of your printed papers.

Why put QR codes on my web site?

QR codes let you go from Printer Material to an electronic device - so why on earth would you want to have them on a website which you'll already be calling up electronically?

1. People print pages out. I do it myself a lot of the time, and then they hand those printed pages to people. I usually recommend that web site pages that are likely to be printed should include their URL so that people can type them and get back there - and now I'm going to recommend that you add in a QR code too

2. There's nothing to stop someone waving a QR code reader at a web page on your screen during a presentation to quickly bookmark the URL, or to transfer a page from their own computer to their mobile phone ...

Can I set up a QR code myself?

Yes - the algorithm is public, and libraries such as the phpqrcode library are available under Open Source - [here] on sourceforge. I have installed this library on one of our servers, and can now generate QR codes as and when I want them.

Installation issues

PHP QR Code requires PHP version 5, built with the GD Library and zlib. Although GD and zlib are both shipped with current source distributions of PHP, you need to ensure that they are built in to your live server. When I tried the library for the first time on our server, I got a fatal error because the function gzuncompress was missing and had to rebuild adding to my previous build (using the config.nice script). The addition is:
  --with-zlib

We already have extensive graphics (GD) support on our server:
  --with-gd
  --with-png-dir=/usr
  --with-jpeg-dir=/usr
  --with-ttf
  --with-freetype-dir=/usr/local
  --enable-gd-native-ttf

so no extra were added for GD. Documentation suggests that --with-gd should be sufficient.

I've installed the code into a separate directory away from the main document tree (to avoid direct access) and added the path to that separate directory into the example code that I'm using. But we have lots of separate demos on our server that we want to keep separate, and for a more regular use I would suggest you use the central library facilities provided by PHP.

Running Examples

1. "Hello QR world", if you like:

  <php
  include "$_SERVER[DOCUMENT_ROOT]/../qrcode/qrlib.php";
  QRcode::png("http://www.wellho.net/course/index.html",
      "/home/wellho/public_html/qr/demo.png","L",4,2);
  ?>
  <html>
  <body>
  Here it is: <br /><img src="demo.png" />
  <body>
  <html>


Here its is running:

A QR codeCalls in the library (qrlib.php pulls in other files as needed) and generates a QR code image for http:// www.wellho.net/ course/ index.html in the file /home /wellho /public_htm l/qr /demo.png . The lowest of the four levels of validation bits is used ("L"), each blob is 4 pixels square, and there is a 2 pixel border. The HTML code send out to the browser then calls up the image.

I've had to prepare the way by ensuring that demo.png is writable by the web server ...

Images can be directly generated and output too, and by using a variable to pass in the URL they can be generalised. Here's a snippet of code from such an image generator:
  include "$_SERVER[DOCUMENT_ROOT]/../qrcode/qrlib.php";
  QRcode::png($url,false,"L",4,2);

with the false flag indicating direct output to the browser; this means that the URL of the PHP script needs to be called up in an <img src="***"> format, where *** is the URL of the code generator and any GET parameters needed to tell it the URL.

Performance and security issues

The same parameters in to QRcode::png will generate the same graphic each time ... and there is an element of resource needed in the generation with could be significant on a very busy server. Why do the same work time after time - why not store common codes with a caching mechanism? There is such a mechanism available in the PHP QR code library.


And if you put a dynamic QR code generator on your site, you'll certainly want to add some security tests to ensure that you're not providing a very public service to provide some very naughty links. I've limited ours to providing links only to specified domains, and to validating the page name too. Try running my dynamic generator on a naughty link, and you'll get a very nice picture of a horse that's totally useless for linking!

Source code of my dynamic generator available [here] in the Maps, Graphics and Geographics module of our PHP Techniques course.

QR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other countries.


(written 2012-01-18, updated 2012-01-28)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
G914 - Well House Consultants - Other Software
  [4303] Libre Office - unable to get past REOPEN WINDOWS? question - (2014-09-22)
  [4038] Using Pygments to colour our training examples - (2013-03-10)
  [3991] Email from Christopher Columbus to announce finding America? - (2013-01-29)
  [3896] An email marathon - (2012-10-15)
  [3648] iPad and iPhone programming - our seminar weekend with Xcode - (2012-03-11)
  [3599] Seeing how Melksham has changed over the years, via an iPad - (2012-01-30)
  [3213] Should I use Open Source or Commercial software? - (2011-03-26)
  [2906] Switching from Adobe Photoshop to Gimp - testing it on animals - (2010-08-06)
  [2600] Go Programming Language and Courses? - (2010-01-26)
  [2470] Windows 7 and Open Source Programming - (2009-10-22)
  [2191] RT @brento - a valuable source for the twitter newbie - (2009-05-20)
  [2106] Learning to Twitter / what is Twitter? - (2009-03-28)
  [75] It's just not cricket - (2004-10-06)

H309 - PHP - Maps, Graphics and Geographics
  [4178] Where are you? How to write a geosensitive application - (2013-09-18)
  [3817] Fpdf - generating .pdf documents easily from your PHP program - (2012-07-24)
  [3734] QR codes with marketing logos embedded - (2012-05-16)
  [3536] UK Mapping Data - and more to come - under government Open Data measures - (2011-12-03)
  [3447] Needle in a haystack - finding the web server overload - (2011-09-18)
  [3211] Computer Graphics in PHP - World (incoming data) to Pixel (screen) conversion - (2011-03-24)
  [3197] Finding and diverting image requests from rogue domains - (2011-03-08)
  [3133] An image from a website that occasionally comes out as hyroglyphics - (2011-01-14)
  [3027] Server logs - drawing a graph of gathered data - (2010-11-03)
  [2939] Protecting your images from use out of context - (2010-08-29)
  [2729] Uploading a document or image to its own URL via a browser - (2010-04-18)
  [2675] Redirecting to your main domain for correct security keys - (2010-03-13)
  [2583] Reducing image size on digital photos - PHP - (2010-01-17)
  [2390] Dynamic / changing images on your web page - (2009-09-01)
  [2361] Geocoding - converting address to latitude / Longitude with PHP via Google - (2009-08-14)
  [2343] World Flags in your PHP pages - (2009-08-10)
  [1956] Images for Christmas - (2008-12-21)
  [1923] Making it all worthwhile - (2008-12-04)
  [1756] Ever had One of THOSE mornings? - (2008-08-16)
  [1752] Dynamic maps / geographics in PHP - (2008-08-13)
  [1734] All around the world? - (2008-08-03)
  [1724] addslashes v mysql_real_escape_string in PHP - (2008-07-27)
  [1628] Gant charts - drawing them with a PHP script - (2008-05-03)
  [1391] Ordnance Survey Grid Reference to Latitude / Longitude - (2007-10-14)
  [1390] Converting from postal address to latitude / longitude - (2007-10-13)
  [1389] Controlling and labelling Google maps via PHP - (2007-10-13)
  [1194] Drawing hands on a clock face - PHP - (2007-05-19)
  [1104] Drawing dynamic graphs in PHP - (2007-03-09)
  [937] Display an image from a MySQL database in a web page via PHP - (2006-11-22)
  [665] PHP Image viewing application - (2006-04-01)
  [563] Merging pictures using PHP and GD - (2006-01-13)
  [320] Ordnance Survey - using a 'Get a map' - (2005-05-22)


Back to
Expanding a list of parameters in Tcl - {*} and eval
Previous and next
or
Horse's mouth home
Forward to
The changing Hotel and Bed and Breakfast business in Melksham
Some other Articles
Learning about how to help people learning - and retaining
C++ Courses - do I get official certification at the end of my Well House course?
Emergency First Aid Provision at Well House Manor - part of the service
The changing Hotel and Bed and Breakfast business in Melksham
QR codes - graphics images that provide quick phone links
Expanding a list of parameters in Tcl - {*} and eval
Tcl collections - lists, dicts and array
Perl - calls to methods that use => - what do they mean?
Melksham Area - buses, trains, cycles, and roads. Meeting, 17.1.2012
Transport in Cambridgeshire - seen by an outside observer. What can Wiltshire learn?
4300 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3584_QR- ... links.html • PAGE BUILT: Thu Sep 18 15:30:25 2014 • BUILD SYSTEM: WomanWithCat