Barcodes and QR codes in PHP

For a project I am working on right now, I needed to generate barcodes and QR codes. Looking around for solutions for the barcodes I quickly found Zend_Barcode (thanks to someone pointing me to it, by the way. I had not expected a barcode generator in Zend). For QR, it was slightly harder to find a good solution. A quick question on Twitter helped a lot. In the end, it boiled down to two options: PHP QR Code and using the Google Chart API.

Barcodes first

First, let's have a look at barcodes. For this project, I will be working on some shipping labels. Postal services can be very strict in their demands on the labels (and rightfully so), so it was a nice surprise to see that Zend_Barcode - aside from supporting the regular standards - has support for several of the postal service standards, like Identcode (used by German postal service), Postnet and Royal Mail. This will surely be really important for my project.

Using Zend_Barcode is really easy. I used my autoloader to autoload the Zend library in my project. Obviously, I had to also include the dependencies of Zend_Barcode (Zend_Loader, Zend_Validate, Zend_Exception and Zend_Registry). After that, it's just setting up the right options based on the request, and outputting the barcode:
As you can see, it's just a matter of fetching the right options from the request, setting the response content type, and calling the Zend_Barcode factory to create the barcode, then render it. It doesn't get any easier.

Now for QR

Now for QR I still had two options left. Usually, when I have two options left, and one is Google, I go for the Google solution. Why? Well, Google usually makes it really easy to use their API, is solid, and is always available. Oh, and *fast*. However, for this project, I decided against this. The main reason for this is that my application may end up running inside a hugely firewalled corporate network with very limited connectivity to the outside world. So I needed something stand-alone for this. The PHP QR Library seemed like a very decent solution and came recommended by people whom I trust a lot on this.

Using PHP QR is possible even simpler than using the Barcode, because it's a single standard so doesn't really have rendering options. So it's just passing along the information that needs to be in the QR code to the library and having it generate the graphic.
I'm loading the qrlib file here (which includes all the library files), setting the content type and then simply calling QRcode::png() to have the library output a PNG for the passed text. That's it!


Add comment

Comments

gravatar ammonia nitrate fertilizer: you will also be able to see great results on your lawn just by spraying on your sod during the late afternoon (as the microbes are kept protected from the harsh rays of the sun). the gardeningguru's organic lawn care manual organic fertilizers are the best type to use because the are slow-acting. sort by: tree protection and fertilizer: whether your trees need a dressing for wounds or just need a vitamin boost, you can find all the tree fertilizers miracle gro fruit and citrus tree fertilizer spikes.
March 6, 2013
gravatar Dana: I am delighted to comment on your post, your post has the power to get many comments, thanks for the wonderful post.
March 6, 2013
gravatar Emily: Good post, I have just stumbled it, Thanks.
March 13, 2013
gravatar Our FOG: Very value able post, it keep me onto reading your whole story.
April 1, 2013
gravatar cereal iron magnet experiment: by all means you can show them a dead animal that has been hit by a car. it is important to spare time to eat, and the time is now. nut and seed products (129). how to choose a headache free boyfriend?
May 17, 2013

Php5_zce_logo

Tags

1337 2008 2010 2011 4developers access modifiers accessibility AdaLovelaceDay09 advent agavi agile alfred amsterdam amsterdamphp apache api apple article articles atk atkMetaNode audioscrobbler autoloading automation azure backwards compatibility barcelona barcodes bash bbc bbq beatstad belgium best practices bittorrent blogging blogs boards of canada book books bughuntday bundle caching cake cal evans calendar career cat cerf certificate cfp cilex clear cms cologne common sense communities community components composer conference conferences contest continuous integration contribute contribution crisis css curl custom d-day data migration datetime DbFinderPlugin decorator decorators deployment deps devdays development directoryindex directoryiterator docblox doctrine doctrine2 documentation download dpc dpc09 dpc10 dpc11 DPC2008 dreamhost drupal dv7 eclipse ed editors efficiency enterprise errors event events expertise ezcomponents facebook filter-branch filteriterator finland flickr fork framework frameworks free ticket freelance freeze frontend fun game games geoip germany getting real git github globiterator gnome-do google google calendar googletalk graceful degradation hack hackers hidden gem hiphop howto hp HR html http i386 ibuildings icann ide ideasofmarch idm imovie inclusivity indy ingewikkeld integration international php conference internet interview ipad IPC ipc ipc08 ipc10 ipc11se iterators iterm2 javascript jenkins jenkins-php job job openings jobeet john peel joomla joomladays kiva kubuntu launcher launchy left on the web libcurl libraries library lighttpd lime linktuesday linux live london loudblog m2ts mac magazines malware mambo manchester marjolein mediterra meeting meme meta methodology micro-financing microframework microsoft migration movie music mysql namespace namespaces netbeans netherlands newsfire nllgg northeastphp nos odmarco open source opinion ORM osx paradiso paris partnership pavilion pear pecl performance personal pfc10 pfc11 pfcongres pfcongrez pfz pfz.nl photo php PHP php5.3 phpabstract phpazure phpBB phpbb phpbelgium phpbenelux phpbnl10 phpday phpdoc phpdocumentor phpgg phpitalia phpnw phpnw08 phpnw11 phpnw12 phpstorm phptek phptek09 phpuk2009 phpUnderControl phpunit php|architect php|tek podcast politics portability postcrossing presentation presentations private projects protected prototype PSR-0 public python qa qr codes re2c recruiting refactoring review rewrite ruby on rails san francisco schedule scifi script security sensio seven things sexism sfdaycgn sflive2011 shell scripting silex simplexml slides smfony software sogeti solar sound speakers spl ssh standard standards star trek static steer strings stylesheets subversion symfony symfony live symfony2 Symfony2 symfonycamp symfonyday symfonylive symfonyUnderControlPlugin talk talks tech techademy technology techportal tek09 telecommuting terratec terrorism testfest testing textmate textpattern the right tool timeout tips tld todo tomas tools training twig uncon unet usability usergroup validation vhost video vim vinyl virus warp webinar weblogging webservices wiki windows winphp women wordpress work workshop world world of warcraft wpi writing wunderlist xml xpath xsd yara year youtube zc11 ZCE zemanta zend zend framework zend server zend studio zendcon Zend_Form zite
© 2004 - 2013 Stefan Koopmanschap + Powered by Symfony, photos powered by Flickr, links powered by Delicious, Shanghai smilies by Iconbuffet. Feeds: rss / atom. Left on the Web v4.4.0.1