Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#3 Intermediate commit

  • Loading branch information...
commit 76bdb32fecfd2fbeb37b17c4dc2eda82783135c7 1 parent f3f2b62
@Gemorroj Gemorroj authored
View
4 Image/Barcode2.php
@@ -100,11 +100,11 @@ public static function draw($text,
throw new Image_Barcode2_Exception('Invalid barcode type ' . $type);
}
- if (!include_once 'Image/Barcode2/' . $type . '.php') {
+ if (!include_once 'Image/Barcode2/' . ucfirst($type) . '.php') {
throw new Image_Barcode2_Exception($type . ' barcode is not supported');
}
- $classname = 'Image_Barcode2_' . $type;
+ $classname = 'Image_Barcode2_' . ucfirst($type);
$obj = new $classname(new Image_Barcode2_Writer());
View
236 Image/Barcode2/Code39.php
@@ -1,236 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
-
-/**
- * Image_Barcode2_Code39 class
- *
- * Image_Barcode2_Code39 creates Code 3 of 9 ( Code39 ) barcode images. It's
- * implementation borrows heavily for the perl module GD::Barcode::Code39
- *
- * PHP versions 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Ryan Briones <ryanbriones@webxdesign.org>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Image_Barcode2
- */
-
-require_once 'Image/Barcode2/Driver.php';
-require_once 'Image/Barcode2/Common.php';
-require_once 'Image/Barcode2/DualWidth.php';
-require_once 'Image/Barcode2/Exception.php';
-
-/**
- * Image_Barcode2_Code39 class
- *
- * Package which provides a method to create Code39 using GD library.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Ryan Briones <ryanbriones@webxdesign.org>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Image_Barcode2
- * @since Image_Barcode2 0.5
- */
-class Image_Barcode2_code39 extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualWidth
-{
- /**
- * Coding map
- * @var array
- */
- var $_coding_map = array(
- '0' => '000110100',
- '1' => '100100001',
- '2' => '001100001',
- '3' => '101100000',
- '4' => '000110001',
- '5' => '100110000',
- '6' => '001110000',
- '7' => '000100101',
- '8' => '100100100',
- '9' => '001100100',
- 'A' => '100001001',
- 'B' => '001001001',
- 'C' => '101001000',
- 'D' => '000011001',
- 'E' => '100011000',
- 'F' => '001011000',
- 'G' => '000001101',
- 'H' => '100001100',
- 'I' => '001001100',
- 'J' => '000011100',
- 'K' => '100000011',
- 'L' => '001000011',
- 'M' => '101000010',
- 'N' => '000010011',
- 'O' => '100010010',
- 'P' => '001010010',
- 'Q' => '000000111',
- 'R' => '100000110',
- 'S' => '001000110',
- 'T' => '000010110',
- 'U' => '110000001',
- 'V' => '011000001',
- 'W' => '111000000',
- 'X' => '010010001',
- 'Y' => '110010000',
- 'Z' => '011010000',
- '-' => '010000101',
- '*' => '010010100',
- '+' => '010001010',
- '$' => '010101000',
- '%' => '000101010',
- '/' => '010100010',
- '.' => '110000100',
- ' ' => '011000100'
- );
-
- /**
- * Class constructor
- *
- * @param Image_Barcode2_Writer $writer Library to use.
- */
- public function __construct(Image_Barcode2_Writer $writer)
- {
- parent::__construct($writer);
- $this->setBarcodeHeight(50);
- $this->setBarcodeWidthThin(1);
- $this->setBarcodeWidthThick(3);
- }
-
-
- /**
- * Validate barcode
- *
- * @throws Image_Barcode2_Exception
- */
- public function validate()
- {
- // Check barcode for invalid characters
- if (preg_match("/[^0-9A-Z\-*+\$%\/. ]/", $this->getBarcode())) {
- throw new Image_Barcode2_Exception('Invalid barcode');
- }
- }
-
-
- /**
- * Make an image resource using the GD image library
- *
- * @return resource The Barcode Image (TM)
- *
- * @author Ryan Briones <ryanbriones@webxdesign.org>
- */
- public function draw()
- {
- $text = $this->getBarcode();
-
- // add start and stop * characters
- $final_text = '*' . $text . '*';
-
- $barcode = '';
- foreach (str_split($final_text) as $character) {
- $barcode .= $this->_dumpCode($this->_coding_map[$character] . '0');
- }
-
- $barcode_len = strlen($barcode);
-
- // Create GD image object
- $img = $this->getWriter()->imagecreate($barcode_len, $this->getBarcodeHeight());
-
- // Allocate black and white colors to the image
- $black = $this->getWriter()->imagecolorallocate($img, 0, 0, 0);
- $white = $this->getWriter()->imagecolorallocate($img, 255, 255, 255);
- $font_height = $this->getWriter()->imagefontheight($this->getFontSize());
- $font_width = $this->getWriter()->imagefontwidth($this->getFontSize());
-
- // fill background with white color
- $this->getWriter()->imagefill($img, 0, 0, $white);
-
- // Initialize X position
- $xpos = 0;
-
- // draw barcode bars to image
- foreach (str_split($barcode) as $character_code) {
- if ($character_code == 0) {
- $this->getWriter()->imageline(
- $img,
- $xpos,
- 0,
- $xpos,
- $this->getBarcodeHeight() - $font_height - 1,
- $white
- );
- } else {
- $this->getWriter()->imageline(
- $img,
- $xpos,
- 0,
- $xpos,
- $this->getBarcodeHeight() - $font_height - 1,
- $black
- );
- }
-
- $xpos++;
- }
-
- // draw text under barcode
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- ($barcode_len - $font_width * strlen($text)) / 2,
- $this->getBarcodeHeight() - $font_height,
- $text,
- $black
- );
-
-
- return $img;
- }
-
-
- /**
- * _dumpCode is a PHP implementation of dumpCode from the Perl module
- * GD::Barcode::Code39. I royally screwed up when trying to do the thing
- * my own way the first time. This way works.
- *
- * @param string $code Code39 barcode code
- *
- * @return string $result barcode line code
- * @access private
- * @author Ryan Briones <ryanbriones@webxdesign.org>
- *
- *
- */
- private function _dumpCode($code)
- {
- $result = '';
- $color = 1; // 1: Black, 0: White
-
- // if $bit is 1, line is wide; if $bit is 0 line is thin
- foreach (str_split($code) as $bit) {
- if ($bit == 1) {
- $result .= str_repeat($color, $this->getBarcodeWidthThick());
- } else {
- $result .= str_repeat($color, $this->getBarcodeWidthThin());
- }
-
- $color = ($color == 0) ? 1 : 0;
- }
-
- return $result;
- }
-}
-
-?>
View
16 Image/Barcode2/Common.php
@@ -1,5 +1,5 @@
<?php
-class Image_Barcode2_Common
+class Image_Barcode2_Common
{
protected $_barcodeheight;
protected $_barcodewidth;
@@ -37,13 +37,20 @@ public function setWriter(Image_Barcode2_Writer $writer)
{
$this->_writer = $writer;
}
-
+
+ /**
+ * Get the image rendering library.
+ *
+ * @return Image_Barcode2_Writer
+ */
public function getWriter()
{
return $this->_writer;
}
/**
+ * Set the barcode
+ *
* @param string $barcode
*/
public function setBarcode($barcode)
@@ -51,6 +58,11 @@ public function setBarcode($barcode)
$this->_barcode = trim($barcode);
}
+ /**
+ * Get the barcode
+ *
+ * @return string
+ */
public function getBarcode()
{
return $this->_barcode;
View
4 Image/Barcode2/Driver.php
@@ -1,5 +1,5 @@
<?php
-interface Image_Barcode2_Driver
+interface Image_Barcode2_Driver
{
/**
* Draws a barcode
@@ -18,7 +18,7 @@ public function setWriter(Image_Barcode2_Writer $writer);
/**
* Set barcode
*
- * @param string $barcode
+ * @param string $barcode barcode
*/
public function setBarcode($barcode);
View
397 Image/Barcode2/code128.php
@@ -1,397 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
-
-/**
- * Image_Barcode2_code128 class
- *
- * Renders Code128 barcodes
- * Code128 is a high density encoding for alphanumeric strings.
- * This module prints the Code128B representation of the most common
- * ASCII characters (32 to 134).
- *
- * These are the components of a Code128 Bar code:
- * - 10 Unit Quiet Zone
- * - 6 Unit Start Character
- * - (n * 6) Unit Message
- * - 6 Unit "Check Digit" Character
- * - 7 Unit Stop Character
- * - 10 Unit Quiet Zone
- *
- * I originally wrote this algorithm in Visual Basic 6 for a Rapid
- * Software Development class, where we printed Code128 B bar codes
- * to read using Cue Cat bar code readers. I rewrote the algorithm
- * using PHP for inclusion in the PEAR Image_Barcode2 project.
- *
- * The Code128B bar codes produced by the algorithm have been validated
- * using my trusty Cue-Cat bar code reader.
- *
- * PHP versions 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Jeffrey K. Brown <jkb@darkfantastic.net>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Image_Barcode2
- */
-
-require_once 'Image/Barcode2/Driver.php';
-require_once 'Image/Barcode2/Common.php';
-require_once 'Image/Barcode2/Exception.php';
-
-/**
- * Code128
- *
- * @category Image
- * @package Image_Barcode2
- * @author Jeffrey K. Brown <jkb@darkfantastic.net>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @link http://pear.php.net/package/Image_Barcode2
- */
-
-class Image_Barcode2_code128 extends Image_Barcode2_Common implements Image_Barcode2_Driver
-{
- var $_code = array();
-
- /**
- * Class constructor
- *
- * @param Image_Barcode2_Writer $writer Library to use.
- */
- public function __construct(Image_Barcode2_Writer $writer)
- {
- parent::__construct($writer);
- $this->setBarcodeHeight(60);
- $this->setBarcodeWidth(1);
-
- $this->_code[0] = "212222"; // " "
- $this->_code[1] = "222122"; // "!"
- $this->_code[2] = "222221"; // "{QUOTE}"
- $this->_code[3] = "121223"; // "#"
- $this->_code[4] = "121322"; // "$"
- $this->_code[5] = "131222"; // "%"
- $this->_code[6] = "122213"; // "&"
- $this->_code[7] = "122312"; // "'"
- $this->_code[8] = "132212"; // "("
- $this->_code[9] = "221213"; // ")"
- $this->_code[10] = "221312"; // "*"
- $this->_code[11] = "231212"; // "+"
- $this->_code[12] = "112232"; // ","
- $this->_code[13] = "122132"; // "-"
- $this->_code[14] = "122231"; // "."
- $this->_code[15] = "113222"; // "/"
- $this->_code[16] = "123122"; // "0"
- $this->_code[17] = "123221"; // "1"
- $this->_code[18] = "223211"; // "2"
- $this->_code[19] = "221132"; // "3"
- $this->_code[20] = "221231"; // "4"
- $this->_code[21] = "213212"; // "5"
- $this->_code[22] = "223112"; // "6"
- $this->_code[23] = "312131"; // "7"
- $this->_code[24] = "311222"; // "8"
- $this->_code[25] = "321122"; // "9"
- $this->_code[26] = "321221"; // ":"
- $this->_code[27] = "312212"; // ";"
- $this->_code[28] = "322112"; // "<"
- $this->_code[29] = "322211"; // "="
- $this->_code[30] = "212123"; // ">"
- $this->_code[31] = "212321"; // "?"
- $this->_code[32] = "232121"; // "@"
- $this->_code[33] = "111323"; // "A"
- $this->_code[34] = "131123"; // "B"
- $this->_code[35] = "131321"; // "C"
- $this->_code[36] = "112313"; // "D"
- $this->_code[37] = "132113"; // "E"
- $this->_code[38] = "132311"; // "F"
- $this->_code[39] = "211313"; // "G"
- $this->_code[40] = "231113"; // "H"
- $this->_code[41] = "231311"; // "I"
- $this->_code[42] = "112133"; // "J"
- $this->_code[43] = "112331"; // "K"
- $this->_code[44] = "132131"; // "L"
- $this->_code[45] = "113123"; // "M"
- $this->_code[46] = "113321"; // "N"
- $this->_code[47] = "133121"; // "O"
- $this->_code[48] = "313121"; // "P"
- $this->_code[49] = "211331"; // "Q"
- $this->_code[50] = "231131"; // "R"
- $this->_code[51] = "213113"; // "S"
- $this->_code[52] = "213311"; // "T"
- $this->_code[53] = "213131"; // "U"
- $this->_code[54] = "311123"; // "V"
- $this->_code[55] = "311321"; // "W"
- $this->_code[56] = "331121"; // "X"
- $this->_code[57] = "312113"; // "Y"
- $this->_code[58] = "312311"; // "Z"
- $this->_code[59] = "332111"; // "["
- $this->_code[60] = "314111"; // "\"
- $this->_code[61] = "221411"; // "]"
- $this->_code[62] = "431111"; // "^"
- $this->_code[63] = "111224"; // "_"
- $this->_code[64] = "111422"; // "`"
- $this->_code[65] = "121124"; // "a"
- $this->_code[66] = "121421"; // "b"
- $this->_code[67] = "141122"; // "c"
- $this->_code[68] = "141221"; // "d"
- $this->_code[69] = "112214"; // "e"
- $this->_code[70] = "112412"; // "f"
- $this->_code[71] = "122114"; // "g"
- $this->_code[72] = "122411"; // "h"
- $this->_code[73] = "142112"; // "i"
- $this->_code[74] = "142211"; // "j"
- $this->_code[75] = "241211"; // "k"
- $this->_code[76] = "221114"; // "l"
- $this->_code[77] = "413111"; // "m"
- $this->_code[78] = "241112"; // "n"
- $this->_code[79] = "134111"; // "o"
- $this->_code[80] = "111242"; // "p"
- $this->_code[81] = "121142"; // "q"
- $this->_code[82] = "121241"; // "r"
- $this->_code[83] = "114212"; // "s"
- $this->_code[84] = "124112"; // "t"
- $this->_code[85] = "124211"; // "u"
- $this->_code[86] = "411212"; // "v"
- $this->_code[87] = "421112"; // "w"
- $this->_code[88] = "421211"; // "x"
- $this->_code[89] = "212141"; // "y"
- $this->_code[90] = "214121"; // "z"
- $this->_code[91] = "412121"; // "{"
- $this->_code[92] = "111143"; // "|"
- $this->_code[93] = "111341"; // "}"
- $this->_code[94] = "131141"; // "~"
- $this->_code[95] = "114113"; // 95
- $this->_code[96] = "114311"; // 96
- $this->_code[97] = "411113"; // 97
- $this->_code[98] = "411311"; // 98
- $this->_code[99] = "113141"; // 99
- $this->_code[100] = "114131"; // 100
- $this->_code[101] = "311141"; // 101
- $this->_code[102] = "411131"; // 102
- }
-
-
- /**
- * Validate barcode
- *
- * @throws Image_Barcode2_Exception
- */
- public function validate()
- {
- //
- }
-
-
- /**
- * Draws a Code128 image barcode
- *
- *
- * @return image The corresponding interleaved 2 of 5 image barcode
- *
- * @access public
- *
- * @author Jeffrey K. Brown <jkb@darkfantastic.net>
- *
- * @internal
- * The draw() method is broken into three sections. First, we take
- * the input string and convert it to a string of barcode widths.
- * Then, we size and allocate the image. Finally, we print the bars to
- * the image along with the barcode text and display it to the beholder.
- *
- */
- public function draw()
- {
- // We start with the Code128 Start Code character. We
- // initialize checksum to 104, rather than calculate it.
- // We then add the startcode to $allbars, the main string
- // containing the bar sizes for the entire code.
- $startcode = $this->_getStartCode();
- $checksum = 104;
- $allbars = $startcode;
- $text = $this->getBarcode();
-
-
- // Next, we read the barcode string that was passed to the
- // method and for each character, we determine the bar
- // pattern and add it to the end of the $allbars string.
- // In addition, we continually add the character's value
- // to the checksum
- for ($i = 0, $all = strlen($text); $i < $all; ++$i) {
- $char = $text[$i];
- $val = $this->_getCharNumber($char);
-
- $checksum += ($val * ($i + 1));
-
- $allbars .= $this->_getCharCode($char);
- }
-
-
- // Then, Take the Mod 103 of the total to get the index
- // of the Code128 Check Character. We get its bar
- // pattern and add it to $allbars in the next section.
- $checkdigit = $checksum % 103;
- $bars = $this->_getNumCode($checkdigit);
-
-
- // Finally, we get the Stop Code pattern and put the
- // remaining pieces together. We are left with the
- // string $allbars containing all of the bar widths
- // and can now think about writing it to the image.
-
- $stopcode = $this->_getStopCode();
- $allbars = $allbars . $bars . $stopcode;
-
- //------------------------------------------------------//
- // Next, we will calculate the width of the resulting
- // bar code and size the image accordingly.
-
- // 10 Pixel "Quiet Zone" in front, and 10 Pixel
- // "Quiet Zone" at the end.
- $barcodewidth = 20;
-
-
- // We will read each of the characters (1,2,3,or 4) in
- // the $allbars string and add its width to the running
- // total $barcodewidth. The height of the barcode is
- // calculated by taking the bar height plus the font height.
-
- for ($i = 0, $all = strlen($allbars); $i < $all; ++$i) {
- $nval = $allbars[$i];
- $barcodewidth += ($nval * $this->getBarcodeWidth());
- }
-
- $barcodelongheight = (int)($this->getWriter()->imagefontheight($this->getFontSize()) / 2)
- + $this->getBarcodeHeight();
-
-
- // Then, we create the image, allocate the colors, and fill
- // the image with a nice, white background, ready for printing
- // our black bars and the text.
-
- $img = $this->getWriter()->imagecreate(
- $barcodewidth,
- $barcodelongheight + $this->getWriter()->imagefontheight($this->getFontSize()) + 1
- );
- $black = $this->getWriter()->imagecolorallocate($img, 0, 0, 0);
- $white = $this->getWriter()->imagecolorallocate($img, 255, 255, 255);
- $this->getWriter()->imagefill($img, 0, 0, $white);
-
-
- //------------------------------------------------------//
- // Finally, we write our text line centered across the
- // bottom and the bar patterns and display the image.
-
-
- // First, print the image, centered across the bottom.
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $barcodewidth / 2 - strlen($text) / 2 * ($this->getWriter()->imagefontwidth($this->getFontSize())),
- $this->getBarcodeHeight() + $this->getWriter()->imagefontheight($this->getFontSize()) / 2,
- $text,
- $black
- );
-
- // We set $xpos to 10 so we start bar printing after
- // position 10 to simulate the 10 pixel "Quiet Zone"
- $xpos = 10;
-
- // We will now process each of the characters in the $allbars
- // array. The number in each position is read and then alternating
- // black bars and spaces are drawn with the corresponding width.
- $bar = 1;
- for ($i = 0, $all = strlen($allbars); $i < $all; ++$i) {
- $nval = $allbars[$i];
- $width = $nval * $this->getBarcodeWidth();
-
- if ($bar == 1) {
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $width - 1,
- $barcodelongheight,
- $black
- );
- $xpos += $width;
- $bar = 0;
- } else {
- $xpos += $width;
- $bar = 1;
- }
- }
-
- return $img;
- }
-
-
- /**
- * Get the Code128 code for a character
- *
- * @param string $char Chacter
- *
- * @return string
- */
- private function _getCharCode($char)
- {
- return $this->_code[ord($char) - 32];
- }
-
-
- /**
- * Get the Start Code for Code128
- *
- * @return string
- */
- private function _getStartCode()
- {
- return '211214';
- }
-
-
- /**
- * Get the Stop Code for Code128
- *
- * @return string
- */
- private function _getStopCode()
- {
- return '2331112';
- }
-
-
- /**
- * Rhe Code128 code equivalent of a character number
- *
- * @param int $index Index
- *
- * @return string
- */
- private function _getNumCode($index)
- {
- return $this->_code[$index];
- }
-
-
- /**
- * Get the Code128 numerical equivalent of a character.
- *
- * @param string $char Character
- *
- * @return int
- */
- private function _getCharNumber($char)
- {
- return ord($char) - 32;
- }
-
-} // class
-
-?>
View
337 Image/Barcode2/ean13.php
@@ -1,337 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
-
-/**
- * Image_Barcode2_ean13 class
- *
- * Renders EAN 13 barcodes
- *
- * PHP versions 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Image
- * @package Image_Barcode
- * @author Didier Fournout <didier.fournout@nyc.fr>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Image_Barcode
- */
-
-require_once 'Image/Barcode2/Driver.php';
-require_once 'Image/Barcode2/Common.php';
-require_once 'Image/Barcode2/Exception.php';
-
-/**
- * Image_Barcode2_ean13 class
- *
- * Package which provides a method to create EAN 13 barcode using GD library.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Didier Fournout <didier.fournout@nyc.fr>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Image_Barcode
- * @since Image_Barcode2 0.4
- */
-class Image_Barcode2_ean13 extends Image_Barcode2_Common implements Image_Barcode2_Driver
-{
- /**
- * Number set
- * @var array
- */
- var $_number_set = array(
- '0' => array(
- 'A' => array(0,0,0,1,1,0,1),
- 'B' => array(0,1,0,0,1,1,1),
- 'C' => array(1,1,1,0,0,1,0)
- ),
- '1' => array(
- 'A' => array(0,0,1,1,0,0,1),
- 'B' => array(0,1,1,0,0,1,1),
- 'C' => array(1,1,0,0,1,1,0)
- ),
- '2' => array(
- 'A' => array(0,0,1,0,0,1,1),
- 'B' => array(0,0,1,1,0,1,1),
- 'C' => array(1,1,0,1,1,0,0)
- ),
- '3' => array(
- 'A' => array(0,1,1,1,1,0,1),
- 'B' => array(0,1,0,0,0,0,1),
- 'C' => array(1,0,0,0,0,1,0)
- ),
- '4' => array(
- 'A' => array(0,1,0,0,0,1,1),
- 'B' => array(0,0,1,1,1,0,1),
- 'C' => array(1,0,1,1,1,0,0)
- ),
- '5' => array(
- 'A' => array(0,1,1,0,0,0,1),
- 'B' => array(0,1,1,1,0,0,1),
- 'C' => array(1,0,0,1,1,1,0)
- ),
- '6' => array(
- 'A' => array(0,1,0,1,1,1,1),
- 'B' => array(0,0,0,0,1,0,1),
- 'C' => array(1,0,1,0,0,0,0)
- ),
- '7' => array(
- 'A' => array(0,1,1,1,0,1,1),
- 'B' => array(0,0,1,0,0,0,1),
- 'C' => array(1,0,0,0,1,0,0)
- ),
- '8' => array(
- 'A' => array(0,1,1,0,1,1,1),
- 'B' => array(0,0,0,1,0,0,1),
- 'C' => array(1,0,0,1,0,0,0)
- ),
- '9' => array(
- 'A' => array(0,0,0,1,0,1,1),
- 'B' => array(0,0,1,0,1,1,1),
- 'C' => array(1,1,1,0,1,0,0)
- )
- );
-
- var $_number_set_left_coding = array(
- '0' => array('A','A','A','A','A','A'),
- '1' => array('A','A','B','A','B','B'),
- '2' => array('A','A','B','B','A','B'),
- '3' => array('A','A','B','B','B','A'),
- '4' => array('A','B','A','A','B','B'),
- '5' => array('A','B','B','A','A','B'),
- '6' => array('A','B','B','B','A','A'),
- '7' => array('A','B','A','B','A','B'),
- '8' => array('A','B','A','B','B','A'),
- '9' => array('A','B','B','A','B','A')
- );
-
- /**
- * Class constructor
- *
- * @param Image_Barcode2_Writer $writer Library to use.
- */
- public function __construct(Image_Barcode2_Writer $writer)
- {
- parent::__construct($writer);
- $this->setBarcodeHeight(50);
- $this->setBarcodeWidth(1);
- }
-
-
- /**
- * Validate barcode
- *
- * @throws Image_Barcode2_Exception
- */
- public function validate()
- {
- // Check barcode for invalid characters
- if (!preg_match('/^[0-9]{13}$/', $this->getBarcode())) {
- throw new Image_Barcode2_Exception('Invalid barcode');
- }
- }
-
-
- /**
- * Draws a EAN 13 image barcode
- *
- *
- * @return image The corresponding Interleaved 2 of 5 image barcode
- *
- * @access public
- *
- * @author Didier Fournout <didier.fournout@nyc.fr>
- */
- public function draw()
- {
- $text = $this->getBarcode();
-
- // Calculate the barcode width
- $barcodewidth = (strlen($text)) * (7 * $this->getBarcodeWidth())
- + 3 * $this->getBarcodeWidth() // left
- + 5 * $this->getBarcodeWidth() // center
- + 3 * $this->getBarcodeWidth() // right
- + $this->getWriter()->imagefontwidth($this->getFontSize()) + 1
- ;
-
- $barcodelongheight = (int)($this->getWriter()->imagefontheight($this->getFontSize()) / 2)
- + $this->getBarcodeHeight();
-
- // Create the image
- $img = $this->getWriter()->imagecreate(
- $barcodewidth,
- $barcodelongheight + $this->getWriter()->imagefontheight($this->getFontSize()) + 1
- );
-
- // Alocate the black and white colors
- $black = $this->getWriter()->imagecolorallocate($img, 0, 0, 0);
- $white = $this->getWriter()->imagecolorallocate($img, 255, 255, 255);
-
- // Fill image with white color
- $this->getWriter()->imagefill($img, 0, 0, $white);
-
- // get the first digit which is the key for creating the first 6 bars
- $key = substr($text, 0, 1);
-
- // Initiate x position
- $xpos = 0;
-
- // print first digit
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $xpos,
- $this->getBarcodeHeight(),
- $key,
- $black
- );
-
- $xpos = $this->getWriter()->imagefontwidth($this->getFontSize()) + 1;
-
- // Draws the left guard pattern (bar-space-bar)
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
- $xpos += $this->getBarcodeWidth();
-
- // Draw left $text contents
- $set_array = $this->_number_set_left_coding[$key];
- for ($idx = 1; $idx < 7; $idx ++) {
- $value = substr($text, $idx, 1);
-
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
-
- foreach ($this->_number_set[$value][$set_array[$idx - 1]] as $bar) {
- if ($bar) {
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
- }
- $xpos += $this->getBarcodeWidth();
- }
- }
-
- // Draws the center pattern (space-bar-space-bar-space)
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
-
-
- // Draw right $text contents
- for ($idx = 7; $idx < 13; $idx ++) {
- $value = substr($text, $idx, 1);
-
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
-
- foreach ($this->_number_set[$value]['C'] as $bar) {
- if ($bar) {
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
- }
- $xpos += $this->getBarcodeWidth();
- }
- }
-
- // Draws the right guard pattern (bar-space-bar)
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
-
- return $img;
- } // function create
-
-} // class
-
-?>
View
297 Image/Barcode2/ean8.php
@@ -1,297 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
-
-/**
- * Image_Barcode2_ean8 class
- *
- * Renders EAN 8 barcodes
- *
- * PHP versions 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Tobias Frost <tobi@coldtobi.de>
- * @author Didier Fournout <didier.fournout@nyc.fr>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id:
- * @link http://pear.php.net/package/Image_Barcode2
- */
-
-require_once 'Image/Barcode2/Driver.php';
-require_once 'Image/Barcode2/Common.php';
-require_once 'Image/Barcode2/Exception.php';
-
-/**
- * Image_Barcode2_ean8 class
- *
- * Package which provides a method to create EAN 13 barcode using GD library.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Tobias Frost <tobi@coldtobi.de>
- * @author Didier Fournout <didier.fournout@nyc.fr>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Image_Barcode2
- */
-class Image_Barcode2_ean8 extends Image_Barcode2_Common implements Image_Barcode2_Driver
-{
- /**
- * Number set
- * @var array
- */
- var $_number_set = array(
- '0' => array(
- 'A' => array(0,0,0,1,1,0,1),
- 'C' => array(1,1,1,0,0,1,0)
- ),
- '1' => array(
- 'A' => array(0,0,1,1,0,0,1),
- 'C' => array(1,1,0,0,1,1,0)
- ),
- '2' => array(
- 'A' => array(0,0,1,0,0,1,1),
- 'C' => array(1,1,0,1,1,0,0)
- ),
- '3' => array(
- 'A' => array(0,1,1,1,1,0,1),
- 'C' => array(1,0,0,0,0,1,0)
- ),
- '4' => array(
- 'A' => array(0,1,0,0,0,1,1),
- 'C' => array(1,0,1,1,1,0,0)
- ),
- '5' => array(
- 'A' => array(0,1,1,0,0,0,1),
- 'C' => array(1,0,0,1,1,1,0)
- ),
- '6' => array(
- 'A' => array(0,1,0,1,1,1,1),
- 'C' => array(1,0,1,0,0,0,0)
- ),
- '7' => array(
- 'A' => array(0,1,1,1,0,1,1),
- 'C' => array(1,0,0,0,1,0,0)
- ),
- '8' => array(
- 'A' => array(0,1,1,0,1,1,1),
- 'C' => array(1,0,0,1,0,0,0)
- ),
- '9' => array(
- 'A' => array(0,0,0,1,0,1,1),
- 'C' => array(1,1,1,0,1,0,0)
- )
- );
-
- /**
- * Class constructor
- *
- * @param Image_Barcode2_Writer $writer Library to use.
- */
- public function __construct(Image_Barcode2_Writer $writer)
- {
- parent::__construct($writer);
- $this->setBarcodeHeight(50);
- $this->setBarcodeWidth(1);
- }
-
-
- /**
- * Validate barcode
- *
- * @throws Image_Barcode2_Exception
- */
- public function validate()
- {
- // Check barcode for invalid characters
- if (!preg_match('/^[0-9]{8}$/', $this->getBarcode())) {
- throw new Image_Barcode2_Exception('Invalid barcode');
- }
- }
-
-
- /**
- * Draws a EAN 8 image barcode
- *
- * @return image The corresponding EAN8 image barcode
- *
- * @access public
- *
- * @author Tobias Frost tobi@coldtobi.de
- * based on the EAN13 code by Didier Fournout <didier.fournout@nyc.fr>
- */
- public function draw()
- {
- $text = $this->getBarcode();
-
- // Calculate the barcode width
- $barcodewidth = (strlen($text)) * (7 * $this->getBarcodeWidth())
- + 3 * $this->getBarcodeWidth() // left
- + 5 * $this->getBarcodeWidth() // center
- + 3 * $this->getBarcodeWidth() // right
- ;
-
- $barcodelongheight = (int)($this->getWriter()->imagefontheight($this->getFontSize()) / 2)
- + $this->getBarcodeHeight();
-
- // Create the image
- $img = $this->getWriter()->imagecreate(
- $barcodewidth,
- $barcodelongheight + $this->getWriter()->imagefontheight($this->getFontSize()) + 1
- );
-
- // Alocate the black and white colors
- $black = $this->getWriter()->imagecolorallocate($img, 0, 0, 0);
- $white = $this->getWriter()->imagecolorallocate($img, 255, 255, 255);
-
- // Fill image with white color
- $this->getWriter()->imagefill($img, 0, 0, $white);
-
- // Initiate x position
- $xpos = 0;
-
- // Draws the left guard pattern (bar-space-bar)
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
- $xpos += $this->getBarcodeWidth();
-
- for ($idx = 0; $idx < 4; $idx ++) {
- $value = substr($text, $idx, 1);
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
- foreach ($this->_number_set[$value]['A'] as $bar) {
- if ($bar) {
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
- }
- $xpos += $this->getBarcodeWidth();
- }
- }
-
- // Draws the center pattern (space-bar-space-bar-space)
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
-
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
-
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
-
-
- // Draw right $text contents
- for ($idx = 4; $idx < 8; $idx ++) {
- $value = substr($text, $idx, 1);
-
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
-
- foreach ($this->_number_set[$value]['C'] as $bar) {
- if ($bar) {
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
- }
- $xpos += $this->getBarcodeWidth();
- }
- }
-
- // Draws the right guard pattern (bar-space-bar)
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
-
- return $img;
- } // function create
-
-} // class
-
-?>
View
213 Image/Barcode2/int25.php
@@ -1,213 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
-
-/**
- * Image_Barcode2_int25 class
- *
- * Renders Interleaved 2 of 5 barcodes
- *
- * PHP versions 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Marcelo Subtil Marcal <msmarcal@php.net>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Image_Barcode2
- */
-
-require_once 'Image/Barcode2/Driver.php';
-require_once 'Image/Barcode2/Common.php';
-require_once 'Image/Barcode2/DualWidth.php';
-require_once 'Image/Barcode2/Exception.php';
-
-/**
- * Image_Barcode2_int25 class
- *
- * Package which provides a method to create Interleaved 2 of 5
- * barcode using GD library.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Marcelo Subtil Marcal <msmarcal@php.net>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Image_Barcode2
- */
-class Image_Barcode2_int25 extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualWidth
-{
- /**
- * Coding map
- * @var array
- */
- var $_coding_map = array(
- '0' => '00110',
- '1' => '10001',
- '2' => '01001',
- '3' => '11000',
- '4' => '00101',
- '5' => '10100',
- '6' => '01100',
- '7' => '00011',
- '8' => '10010',
- '9' => '01010'
- );
-
- /**
- * Class constructor
- *
- * @param Image_Barcode2_Writer $writer Library to use.
- */
- public function __construct(Image_Barcode2_Writer $writer)
- {
- parent::__construct($writer);
- $this->setBarcodeHeight(50);
- $this->setBarcodeWidthThin(1);
- $this->setBarcodeWidthThick(3);
- }
-
-
- /**
- * Validate barcode
- *
- * @throws Image_Barcode2_Exception
- */
- public function validate()
- {
- // Check barcode for invalid characters
- if (!preg_match('/[0-9]/', $this->getBarcode())) {
- throw new Image_Barcode2_Exception('Invalid barcode');
- }
- }
-
-
- /**
- * Draws a Interleaved 2 of 5 image barcode
- *
- * @return image The corresponding Interleaved 2 of 5 image barcode
- *
- * @access public
- *
- * @author Marcelo Subtil Marcal <msmarcal@php.net>
- * @since Image_Barcode2 0.3
- */
- public function draw()
- {
- $text = $this->getBarcode();
-
- // if odd $text lenght adds a '0' at string beginning
- $text = strlen($text) % 2 ? '0' . $text : $text;
-
- // Calculate the barcode width
- $barcodewidth = (strlen($text))
- * (3 * $this->getBarcodeWidthThin() + 2 * $this->getBarcodeWidthThick())
- + (strlen($text))
- * 2.5
- + (7 * $this->getBarcodeWidthThin() + $this->getBarcodeWidthThick()) + 3;
-
- // Create the image
- $img = $this->getWriter()->imagecreate($barcodewidth, $this->getBarcodeHeight());
-
- // Alocate the black and white colors
- $black = $this->getWriter()->imagecolorallocate($img, 0, 0, 0);
- $white = $this->getWriter()->imagecolorallocate($img, 255, 255, 255);
-
- // Fill image with white color
- $this->getWriter()->imagefill($img, 0, 0, $white);
-
- // Initiate x position
- $xpos = 0;
-
- // Draws the leader
- for ($i = 0; $i < 2; $i++) {
- $elementwidth = $this->getBarcodeWidthThin();
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $elementwidth - 1,
- $this->getBarcodeHeight(),
- $black
- );
- $xpos += $elementwidth;
- $xpos += $this->getBarcodeWidthThin();
- $xpos ++;
- }
-
- // Draw $text contents
- $all = strlen($text);
-
- // Draw 2 chars at a time
- for ($idx = 0; $idx < $all; $idx += 2) {
- $oddchar = substr($text, $idx, 1);
- $evenchar = substr($text, $idx + 1, 1);
-
- // interleave
- for ($baridx = 0; $baridx < 5; $baridx++) {
-
- // Draws odd char corresponding bar (black)
- $elementwidth = $this->getBarcodeWidthThin();
- if (substr($this->_coding_map[$oddchar], $baridx, 1)) {
- $elementwidth = $this->getBarcodeWidthThick();
- }
-
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $elementwidth - 1,
- $this->getBarcodeHeight(),
- $black
- );
-
- $xpos += $elementwidth;
-
- // Left enought space to draw even char (white)
- $elementwidth = $this->getBarcodeWidthThin();
- if (substr($this->_coding_map[$evenchar], $baridx, 1)) {
- $elementwidth = $this->getBarcodeWidthThick();
- }
-
- $xpos += $elementwidth;
- $xpos ++;
- }
- }
-
-
- // Draws the trailer
- $elementwidth = $this->getBarcodeWidthThick();
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $elementwidth - 1,
- $this->getBarcodeHeight(),
- $black
- );
- $xpos += $elementwidth;
- $xpos += $this->getBarcodeWidthThin();
- $xpos ++;
- $elementwidth = $this->getBarcodeWidthThin();
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $elementwidth - 1,
- $this->getBarcodeHeight(),
- $black
- );
-
- return $img;
- }
-
-} // class
-
-?>
View
198 Image/Barcode2/postnet.php
@@ -1,198 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
-
-/**
- * Image_Barcode2_postnet class
- *
- * Renders PostNet barcodes
- *
- * PHP versions 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Josef "Jeff" Sipek <jeffpc@optonline.net>
- * @copyright 2005 Josef "Jeff" Sipek
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Image_Barcode2
- */
-
- /*
- * Note:
- *
- * The generated barcode must fit the following criteria to be useable
- * by the USPS scanners:
- *
- * When printed, the dimensions should be:
- *
- * tall bar: 1/10 inches = 2.54 mm
- * short bar: 1/20 inches = 1.27 mm
- * density: 22 bars/inch = 8.66 bars/cm
- */
-
-require_once 'Image/Barcode2/Driver.php';
-require_once 'Image/Barcode2/Common.php';
-require_once 'Image/Barcode2/Exception.php';
-
-/**
- * Image_Barcode2_postnet class
- *
- * Package which provides a method to create PostNet barcode using GD library.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Josef "Jeff" Sipek <jeffpc@optonline.net>
- * @copyright 2005 Josef "Jeff" Sipek
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Image_Barcode2
- */
-class Image_Barcode2_postnet extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualHeight
-{
- /**
- * Bar short height
- *
- * @var integer
- */
- var $_barshortheight = 7;
-
- /**
- * Bar tall height
- *
- * @var integer
- */
- var $_bartallheight = 15;
-
- /**
- * Coding map
- * @var array
- */
- var $_coding_map = array(
- '0' => '11000',
- '1' => '00011',
- '2' => '00101',
- '3' => '00110',
- '4' => '01001',
- '5' => '01010',
- '6' => '01100',
- '7' => '10001',
- '8' => '10010',
- '9' => '10100'
- );
-
- /**
- * Class constructor
- *
- * @param Image_Barcode2_Writer $writer Library to use.
- */
- public function __construct(Image_Barcode2_Writer $writer)
- {
- parent::__construct($writer);
- $this->setBarcodeWidth(2);
- }
-
-
- /**
- * Validate barcode
- *
- * @throws Image_Barcode2_Exception
- */
- public function validate()
- {
- // Check barcode for invalid characters
- if (!preg_match('/[0-9]/', $this->getBarcode())) {
- throw new Image_Barcode2_Exception('Invalid barcode');
- }
- }
-
-
- /**
- * Draws a PostNet image barcode
- *
- * @return image The corresponding Interleaved 2 of 5 image barcode
- *
- * @access public
- *
- * @author Josef "Jeff" Sipek <jeffpc@optonline.net>
- * @since Image_Barcode2 0.3
- */
-
- public function draw()
- {
- $text = $this->getBarcode();
-
- // Calculate the barcode width
- $barcodewidth = (strlen($text)) * 2 * 5 * $this->getBarcodeWidth()
- + $this->getBarcodeWidth() * 3;
-
- // Create the image
- $img = $this->getWriter()->imagecreate($barcodewidth, $this->_bartallheight);
-
- // Alocate the black and white colors
- $black = $this->getWriter()->imagecolorallocate($img, 0, 0, 0);
- $white = $this->getWriter()->imagecolorallocate($img, 255, 255, 255);
-
- // Fill image with white color
- $this->getWriter()->imagefill($img, 0, 0, $white);
-
- // Initiate x position
- $xpos = 0;
-
- // Draws the leader
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->_bartallheight,
- $black
- );
-
- $xpos += 2 * $this->getBarcodeWidth();
-
- // Draw $text contents
- for ($idx = 0, $all = strlen($text); $idx < $all; $idx++) {
- $char = substr($text, $idx, 1);
-
- for ($baridx = 0; $baridx < 5; $baridx++) {
- $elementheight = $this->_barshortheight;
-
- if (substr($this->_coding_map[$char], $baridx, 1)) {
- $elementheight = 0;
- }
-
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- $elementheight,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->_bartallheight,
- $black
- );
-
- $xpos += 2 * $this->getBarcodeWidth();
- }
- }
-
- // Draws the trailer
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->_bartallheight,
- $black
- );
-
- return $img;
- }
-
-} // class
-
-?>
View
372 Image/Barcode2/upca.php
@@ -1,372 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
-
-/**
- * Image_Barcode2_upca class
- *
- * Renders UPC-A barcodes
- *
- * PHP versions 5
- *
- * LICENSE: This source file is subject to version 3.0 of the PHP license
- * that is available through the world-wide-web at the following URI:
- * http://www.php.net/license/3_0.txt. If you did not receive a copy of
- * the PHP License and are unable to obtain it through the web, please
- * send a note to license@php.net so we can mail you a copy immediately.
- *
- * @category Image
- * @package Image_Barcode2
- * @author Jeffrey K. Brown <jkb@darkfantastic.net>
- * @author Didier Fournout <didier.fournout@nyc.fr>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Image_Barcode2
- */
-
-require_once 'Image/Barcode2/Driver.php';
-require_once 'Image/Barcode2/Common.php';
-require_once 'Image/Barcode2/Exception.php';
-
-/**
- * Image_Barcode2_upca class
- *
- * Package which provides a method to create UPC-A barcode using GD library.
- *
- * Slightly Modified ean13.php to get upca.php I needed a way to print
- * UPC-A bar codes on a PHP page. The Image_Barcode2 class seemed like
- * the best way to do it, so I modified ean13 to print in the UPC-A format.
- * Checked the bar code tables against some documentation below (no errors)
- * and validated the changes with my trusty cue-cat.
- * http://www.indiana.edu/~atmat/units/barcodes/bar_t4.htm
- *
- * @category Image
- * @package Image_Barcode2
- * @author Jeffrey K. Brown <jkb@darkfantastic.net>
- * @author Didier Fournout <didier.fournout@nyc.fr>
- * @copyright 2005 The PHP Group
- * @license http://www.php.net/license/3_0.txt PHP License 3.0
- * @version Release: @package_version@
- * @link http://pear.php.net/package/Image_Barcode2
- */
-class Image_Barcode2_upca extends Image_Barcode2_Common implements Image_Barcode2_Driver
-{
- /**
- * Number set
- * @var array
- */
- var $_number_set = array(
- '0' => array(
- 'L' => array(0,0,0,1,1,0,1),
- 'R' => array(1,1,1,0,0,1,0)
- ),
- '1' => array(
- 'L' => array(0,0,1,1,0,0,1),
- 'R' => array(1,1,0,0,1,1,0)
- ),
- '2' => array(
- 'L' => array(0,0,1,0,0,1,1),
- 'R' => array(1,1,0,1,1,0,0)
- ),
- '3' => array(
- 'L' => array(0,1,1,1,1,0,1),
- 'R' => array(1,0,0,0,0,1,0)
- ),
- '4' => array(
- 'L' => array(0,1,0,0,0,1,1),
- 'R' => array(1,0,1,1,1,0,0)
- ),
- '5' => array(
- 'L' => array(0,1,1,0,0,0,1),
- 'R' => array(1,0,0,1,1,1,0)
- ),
- '6' => array(
- 'L' => array(0,1,0,1,1,1,1),
- 'R' => array(1,0,1,0,0,0,0)
- ),
- '7' => array(
- 'L' => array(0,1,1,1,0,1,1),
- 'R' => array(1,0,0,0,1,0,0)
- ),
- '8' => array(
- 'L' => array(0,1,1,0,1,1,1),
- 'R' => array(1,0,0,1,0,0,0)
- ),
- '9' => array(
- 'L' => array(0,0,0,1,0,1,1),
- 'R' => array(1,1,1,0,1,0,0)
- )
- );
-
- /**
- * Class constructor
- *
- * @param Image_Barcode2_Writer $writer Library to use.
- */
- public function __construct(Image_Barcode2_Writer $writer)
- {
- parent::__construct($writer);
- $this->setBarcodeHeight(50);
- $this->setBarcodeWidth(1);
- }
-
-
- /**
- * Validate barcode
- *
- * @throws Image_Barcode2_Exception
- */
- public function validate()
- {
- // Check barcode for invalid characters
- if (!preg_match('/[0-9]{12}/', $this->getBarcode())) {
- throw new Image_Barcode2_Exception('Invalid barcode');
- }
- }
-
-
- /**
- * Draws a UPC-A image barcode
- *
- * @return image The corresponding Interleaved 2 of 5 image barcode
- *
- * @author Jeffrey K. Brown <jkb@darkfantastic.net>
- * @author Didier Fournout <didier.fournout@nyc.fr>
- */
- public function draw()
- {
- $text = $this->getBarcode();
-
- // Calculate the barcode width
- $barcodewidth = (strlen($text)) * (7 * $this->getBarcodeWidth())
- + 3 // left
- + 5 // center
- + 3 // right
- + $this->getWriter()->imagefontwidth($this->getFontSize()) + 1
- + $this->getWriter()->imagefontwidth($this->getFontSize()) + 1 // check digit padding
- ;
-
-
- $barcodelongheight = (int)($this->getWriter()->imagefontheight($this->getFontSize()) / 2)
- + $this->getBarcodeHeight();
-
- // Create the image
- $img = $this->getWriter()->imagecreate(
- $barcodewidth,
- $barcodelongheight + $this->getWriter()->imagefontheight($this->getFontSize()) + 1
- );
-
- // Alocate the black and white colors
- $black = $this->getWriter()->imagecolorallocate($img, 0, 0, 0);
- $white = $this->getWriter()->imagecolorallocate($img, 255, 255, 255);
-
- // Fill image with white color
- $this->getWriter()->imagefill($img, 0, 0, $white);
-
- // get the first digit which is the key for creating the first 6 bars
- $key = substr($text, 0, 1);
-
- // Initiate x position
- $xpos = 0;
-
- // print first digit
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $xpos,
- $this->getBarcodeHeight(),
- $key,
- $black
- );
- $xpos = $this->getWriter()->imagefontwidth($this->getFontSize()) + 1;
-
-
- // Draws the left guard pattern (bar-space-bar)
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
-
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
-
- $xpos += $this->getBarcodeWidth();
-
-
- foreach ($this->_number_set[$key]['L'] as $bar) {
- if ($bar) {
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $barcodelongheight,
- $black
- );
- }
- $xpos += $this->getBarcodeWidth();
- }
-
-
-
- // Draw left $text contents
- for ($idx = 1; $idx < 6; $idx ++) {
- $value = substr($text, $idx, 1);
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
-
- foreach ($this->_number_set[$value]['L'] as $bar) {
- if ($bar) {
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
- }
- $xpos += $this->getBarcodeWidth();
- }
- }
-
-
- // Draws the center pattern (space-bar-space-bar-space)
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
-
-
- // Draw right $text contents
- for ($idx = 6; $idx < 11; $idx ++) {
- $value = substr($text, $idx, 1);
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
- foreach ($this->_number_set[$value]['R'] as $bar) {
- if ($bar) {
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
- }
- $xpos += $this->getBarcodeWidth();
- }
- }
-
-
-
- $value = substr($text, 11, 1);
- foreach ($this->_number_set[$value]['R'] as $bar) {
- if ($bar) {
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
-
- }
- $xpos += $this->getBarcodeWidth();
- }
-
-
-
- // Draws the right guard pattern (bar-space-bar)
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
-
- $xpos += $this->getBarcodeWidth();
- // space
- $xpos += $this->getBarcodeWidth();
- // bar
- $this->getWriter()->imagefilledrectangle(
- $img,
- $xpos,
- 0,
- $xpos + $this->getBarcodeWidth() - 1,
- $this->getBarcodeHeight(),
- $black
- );
-
- $xpos += $this->getBarcodeWidth();
-
-
- // Print Check Digit
- $this->getWriter()->imagestring(
- $img,
- $this->getFontSize(),
- $xpos + 1,
- $this->getBarcodeHeight(),
- $value,
- $black
- );
-
- return $img;
- }
-
-} // class
-
-?>
Please sign in to comment.
Something went wrong with that request. Please try again.