home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / Image / Barcode.php next >
Encoding:
PHP Script  |  2005-07-07  |  3.1 KB  |  99 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
  3.  
  4. /**
  5.  * Image_Barcode class
  6.  *
  7.  * Package to render barcodes
  8.  *
  9.  * PHP versions 4
  10.  *
  11.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  12.  * that is available through the world-wide-web at the following URI:
  13.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  14.  * the PHP License and are unable to obtain it through the web, please
  15.  * send a note to license@php.net so we can mail you a copy immediately.
  16.  *
  17.  * @category   Image
  18.  * @package    Image_Barcode
  19.  * @author     Marcelo Subtil Marcal <msmarcal@php.net>
  20.  * @copyright  2005 The PHP Group
  21.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  22.  * @version    CVS: $Id: Barcode.php,v 1.2 2005/05/30 04:31:40 msmarcal Exp $
  23.  * @link       http://pear.php.net/package/Image_Barcode
  24.  */
  25.  
  26. require_once("PEAR.php");
  27.  
  28. /**
  29.  * Image_Barcode class
  30.  *
  31.  * Package which provides a method to create barcode using GD library.
  32.  *
  33.  * @category   Image
  34.  * @package    Image_Barcode
  35.  * @author     Marcelo Subtil Marcal <msmarcal@php.net>
  36.  * @copyright  2005 The PHP Group
  37.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  38.  * @version    Release: @package_version@
  39.  * @link       http://pear.php.net/package/Image_Barcode
  40.  */
  41. class Image_Barcode extends PEAR
  42. {
  43.     /**
  44.      * Draws a image barcode
  45.      *
  46.      * @param  string $text     A text that should be in the image barcode
  47.      * @param  string $type     The barcode type. Supported types:
  48.      *                          Code39 - Code 3 of 9
  49.      *                          int25  - 2 Interleaved 5
  50.      *                          ean13  - EAN 13
  51.      *                          upca   - UPC-A
  52.      * @param  string $imgtype  The image type that will be generated
  53.      *
  54.      * @return image            The corresponding image barcode
  55.      *
  56.      * @access public
  57.      *
  58.      * @author Marcelo Subtil Marcal <msmarcal@php.net>
  59.      * @since  Image_Barcode 0.3
  60.      */
  61.     function draw($text, $type = 'int25', $imgtype = 'png') {
  62.  
  63.         // Check if include file exists
  64.         $barcodepath = PEAR_INSTALL_DIR . DIRECTORY_SEPARATOR . "Image" . DIRECTORY_SEPARATOR . "Barcode";
  65.         $supportedtypes = array();
  66.         if ( $incdir = opendir($barcodepath) ) {
  67.             while ( false != ( $avaiabletype = readdir($incdir) ) ) {
  68.                 if ( strstr($avaiabletype, ".php") ) {
  69.                     $supportedtypes[] = $avaiabletype;
  70.                 }
  71.             }
  72.             closedir($incdir);
  73.         }
  74.  
  75.         if ( in_array($type . ".php", $supportedtypes) ) {
  76.             include_once("Image/Barcode/${type}.php");
  77.         } else {
  78.             return PEAR::raiseError("$type barcode is not supported");
  79.         }
  80.  
  81.         $classname = "Image_Barcode_${type}";
  82.  
  83.         if (!class_exists($classname)) {
  84.             return PEAR::raiseError("Unable to include the Image/Barcode/${type}.php file");
  85.         }
  86.  
  87.         if (!in_array('draw',get_class_methods($classname))) {
  88.             return PEAR::raiseError("Unable to find create method in '$classname' class");
  89.         }
  90.  
  91.         @$obj =& new $classname;
  92.  
  93.         $obj->draw($text, $imgtype);
  94.     }
  95.  
  96. }
  97.  
  98. ?>
  99.