Image_Barcode
[ class tree: Image_Barcode ] [ index: Image_Barcode ] [ all elements ]

Source for file int25.php

Documentation is available at int25.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
  3. //
  4. // +----------------------------------------------------------------------+
  5. // | PHP version 4.0                                                      |
  6. // +----------------------------------------------------------------------+
  7. // | Copyright (c) 1997-2001 The PHP Group                                |
  8. // +----------------------------------------------------------------------+
  9. // | This source file is subject to version 3.0 of the PHP license,       |
  10. // | that is bundled with this package in the file LICENSE, and is        |
  11. // | available at through the world-wide-web at                           |
  12. // | http://www.php.net/license/3_0.txt.                                  |
  13. // | If you did not receive a copy of the PHP license and are unable to   |
  14. // | obtain it through the world-wide-web, please send a note to          |
  15. // | license@php.net so we can mail you a copy immediately.               |
  16. // +----------------------------------------------------------------------+
  17. // | Author: Marcelo Subtil Marcal <jason@unleashed.com.br>               |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: int25.php,v 1.2 2003/01/21 11:46:20 jason Exp $
  21. //
  22.  
  23. require_once "PEAR.php";
  24. require_once "Image/Barcode.php";
  25.  
  26. /**
  27.  * Class to create a Interleaved 2 of 5 barcode
  28.  *
  29.  * @author Marcelo Subtil Marcal <jason@conectiva.com.br>
  30.  */
  31.  
  32. class Image_Barcode_int25 extends Image_Barcode
  33. {
  34.     /**
  35.      * Barcode type
  36.      * @var string 
  37.      */
  38.     var $_type 'int25';
  39.  
  40.     /**
  41.      * Barcode height
  42.      *
  43.      * @var integer 
  44.      */
  45.     var $_barcodeheight = 50;
  46.  
  47.     /**
  48.      * Bar thin width
  49.      *
  50.      * @var integer 
  51.      */
  52.     var $_barthinwidth = 1;
  53.  
  54.     /**
  55.      * Bar thick width
  56.      *
  57.      * @var integer 
  58.      */
  59.     var $_barthickwidth = 3;
  60.  
  61.     /**
  62.      * Coding map
  63.      * @var array 
  64.      */
  65.     var $_coding_map = array(
  66.            '0' => '00110',
  67.            '1' => '10001',
  68.            '2' => '01001',
  69.            '3' => '11000',
  70.            '4' => '00101',
  71.            '5' => '10100',
  72.            '6' => '01100',
  73.            '7' => '00011',
  74.            '8' => '10010',
  75.            '9' => '01010'
  76.         );
  77.  
  78.     function draw($text$imgtype 'png')
  79.     {
  80.  
  81.         $text trim($text);
  82.  
  83.         if (!preg_match("/[0-9]/",$text)) return;
  84.  
  85.         // if odd $text lenght adds a '0' at string beginning
  86.         $text strlen($text% 2 ? '0' $text $text;
  87.  
  88.         // Calculate the barcode width
  89.         $barcodewidth (strlen($text)) (3 * $this->_barthinwidth + 2 * $this->_barthickwidth+
  90.             (strlen($text)) * 2.5 +
  91.             (7 * $this->_barthinwidth $this->_barthickwidth+ 3;
  92.  
  93.         // Create the image
  94.         $img = ImageCreate($barcodewidth$this->_barcodeheight);
  95.  
  96.         // Alocate the black and white colors
  97.         $black = ImageColorAllocate($img000);
  98.         $white = ImageColorAllocate($img255255255);
  99.  
  100.         // Fill image with white color
  101.         imagefill($img00$white);
  102.  
  103.         // Initiate x position
  104.         $xpos = 0;
  105.  
  106.         // Draws the leader
  107.         for ($i=0; $i < 2; $i++{
  108.             $elementwidth $this->_barthinwidth;
  109.             imagefilledrectangle($img$xpos0$xpos $elementwidth - 1$this->_barcodeheight$black);
  110.             $xpos += $elementwidth;
  111.             $xpos += $this->_barthinwidth;
  112.             $xpos ++;
  113.         }
  114.  
  115.         // Draw $text contents
  116.         for ($idx = 0; $idx strlen($text)$idx += 2{       // Draw 2 chars at a time
  117.             $oddchar  substr($text$idx1);                 // get odd char
  118.             $evenchar substr($text$idx + 11);             // get even char
  119.  
  120.             // interleave
  121.             for ($baridx = 0; $baridx < 5; $baridx++{
  122.  
  123.                 // Draws odd char corresponding bar (black)
  124.                 $elementwidth (substr($this->_coding_map[$oddchar]$baridx1)) ?  $this->_barthickwidth $this->_barthinwidth;
  125.                 imagefilledrectangle($img$xpos0$xpos $elementwidth - 1$this->_barcodeheight$black);
  126.                 $xpos += $elementwidth;
  127.  
  128.                 // Left enought space to draw even char (white)
  129.                 $elementwidth (substr($this->_coding_map[$evenchar]$baridx1)) ?  $this->_barthickwidth $this->_barthinwidth;
  130.                 $xpos += $elementwidth
  131.                 $xpos ++;
  132.             }
  133.         }
  134.  
  135.  
  136.         // Draws the trailer
  137.         $elementwidth $this->_barthickwidth;
  138.         imagefilledrectangle($img$xpos0$xpos $elementwidth - 1$this->_barcodeheight$black);
  139.         $xpos += $elementwidth;
  140.         $xpos += $this->_barthinwidth;
  141.         $xpos ++;
  142.         $elementwidth $this->_barthinwidth;
  143.         imagefilledrectangle($img$xpos0$xpos $elementwidth - 1$this->_barcodeheight$black);
  144.  
  145.         // Send image to browser
  146.         switch($imgtype{
  147.  
  148.             case 'gif':
  149.                 header("Content-type: image/gif");
  150.                 imagegif($img);
  151.                 imagedestroy($img);
  152.             break;
  153.  
  154.             case 'jpg':
  155.                 header("Content-type: image/jpg");
  156.                 imagejpeg($img);
  157.                 imagedestroy($img);
  158.             break;
  159.  
  160.             default:
  161.                 header("Content-type: image/png");
  162.                 imagepng($img);
  163.                 imagedestroy($img);
  164.             break;
  165.  
  166.         }
  167.  
  168.         return;
  169.  
  170.     // function create
  171.  
  172. // class

Documentation generated on Mon, 11 Mar 2019 14:21:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.