Bardcodes using PHP Pear Image_Barcode

Management of delegate registration at open source conferences has been an issue for quite some time - the main problem is that usually there are no online payment options and the queue gets very long specially on the first day. Late last year I had an opportunity to deploy something which made me feel "we should have done this years ago!" Using Bar codes on delegate registration cards. This saved us a lot of time on not having to enter the delegate code while distributing delegate kits and also at the food court.

If you want a quick premier on Barcode I suggest you read this. In this post I will quickly outline how Bar codes can put on any image using the Pear class Image_Barcode, the pear page shows it as unmaintained but the class itself does the job pretty well.

Below is a somewhat simplified code for printing the bar code on a delegate card

PHP:
  1. // Get the magic of bar code creation in your script
  2. require_once("Image/Barcode.php");
  3.  
  4. // Create the barcode object
  5. $barcode = new Image_Barcode;
  6.  
  7. // Create the barcode image resource using the draw method
  8. // The first param is the string you want to code into the bars
  9. $barCodeImg = $bc->draw("587e0838", "Code39", "png", false);
  10.  
  11. // Create the ticket image
  12. $ticketImg = ImageCreateFromPNG("ticket.png");
  13.  
  14. // Put in code to write whatever you want on the ticket image here
  15. // eg: The delegate's name and organisation etc
  16.  
  17. // Merge the Bar code image with the ticket image
  18. imagecopymerge($ticketImg, $barCodeImg, 20, 140, 0, 0, 160, 50, 75);
  19.  
  20. // Send proper headers
  21. header("Content-type: image/png");
  22. header('Content-Disposition: inline; filename="foss-in-regcode.png"');
  23.  
  24. // Send the image data
  25. imagepng($img);
  26. imagedestroy($img);

If you coded your script properly you will get an output similar to the the one shown below

Reading this bar code is extremely easy as you get bar code readers which simulate USB keyboards. The readers can also be programmed to add a carriage return at the end to simulate the enter key being pressed. So now all you need is a HTML form with just 1 field, a successful scan will submit this form and what you do with it is up to you :-)


About this entry