QR Codes are pretty cool replacements for standard bar codes. The big question though, is how can we generate them from within a PHP page?
First, download the QR Code 3.1.1 library: http://megaui.net/fukuchi/works/qrencode/index.en.html .
You might also need to install PKG-config ( http://pkg-config.freedesktop.org/ ). You’ll know if you need to do this because when you install the QR Code library, it will tell you that it needs the pkg-config files.
So the steps are:
Install QR Code library:
- cd /path/to/qrencode-3.1.1
- make install
If you have any issues with pkg-config, install it with a standad ./configure && make && make install command.
NOTE: I have already installed ImageMagick and the libpng, libjpeg etc libraries, as part of my PHP installation (see an earlier post).
Now you can create QR Codes from the command line like this:
qrencode -o /path/to/the/image/you/want/to/create “Text you want to encode”
In PHP, you can access this by a command like so:
passthru(“/usr/local/bin/qrencode -o /path/to/image.jpg “Text to encode””);
That will create a QR Code image at the specified location, which you can then reference in PHP.