QR-Code generation in PHP, now with bacon flavor

Monday, April 1, 2013

First of, this is not an April Fool's joke. I actually planed to make one this year, but eventually gave up. Anyway, as some of you who follow me on Twitter may know, I worked on a modern QR-Code library, known as BaconQrCode, the past few weeks. Eventually it is now fully working and the public API can be considered stable.

As a base for my implementation I had choosen the ZXing library library. After writing the first unit tests though I noted that their implementation of the Reed-Solomon codec performed rather bad in PHP, so I exchanged it with the much faster implementation by Phil Karn. As the rest of the library performed quite well and seemed much more logical, I choosed to stay with it instead of a different implementation like qrencode, which formed the base for PHP QR Code.

So far my complete implementation works, at least according to the unit tests and some personal testing. I'd like to encourage you to try it out and give me your feedback. I have implemented three different renderers so far, namely Bitmap (PNG), SVG and EPS. There is still a little bit of work to be done for me, like finishing the code-documentation, adding a few more unit tests and doing a few more PHP-specific optimizations, but all that work won't influence the public API anymore.

So, what are you waiting for? As always, you can find the library in the Bacon repository on GitHub or include it in your application via Packagist. If you are interested in more cool stuff, check out the website of of Bacon.

Oh and before I forget it. I may also add QR-Code decoding in the future. This would really be a feature you won't find in any other QR-Code library for PHP ;)

Comments to this article

  • Avatar of Carabez Reply Carabez Friday, July 11, 2014 4:01 PM


    Does the Qr-code generator Works with zf2?

    Thank in advance!

    • Avatar of Ben Scholzen 'DASPRiD' Reply Ben Scholzen 'DASPRiD' Friday, July 11, 2014 4:02 PM

      Of course.

  • Avatar of dams Reply dams Tuesday, August 19, 2014 1:57 PM

    Does this works with zf1 too ?

    • Avatar of Ben Scholzen 'DASPRiD' Reply Ben Scholzen 'DASPRiD' Tuesday, August 19, 2014 2:41 PM

      There's no reason it wouldn't, as long as you run PHP 5.3 or higher.

  • Avatar of hokrc01 Reply hokrc01 Monday, August 10, 2015 7:44 AM

    Is there anyway to have it generate the png directly to the browser and not to a file first?

    • Avatar of Ben Scholzen 'DASPRiD' Reply Ben Scholzen 'DASPRiD' Monday, August 10, 2015 4:46 PM

      The BaconQrCode\Writer class has a writeString() method, which will give you the bytestream of the PNG (in case you have selected a PNG renderer). You can simply send that to the client with the appropriate headers.

Leave a comment

Please note that your email address will not be shown, it is only used to fetch your avatar image from gravatar.com and for notifications.

 _ __ ___   __ _ _   _ _ __  _   _ 
| '__/ _ \ / _` | | | | '_ \| | | |
| | | (_) | (_| | |_| | |_) | |_| |
|_|  \___/ \__, |\__, | .__/ \__,_|