cvs: pear /Image_Barcode Barcode.php package.xml /Image_Barcode/Barcode Code39.php ean13.php int25.php upca.php /Image_Barcode/docs Readme.txt
/Image_Barcode/docs/examples barcode_img.php test-image-barcode.php

From: Date: Mon, 30 May 2005 04:31:42 +0000
Subject: cvs: pear /Image_Barcode Barcode.php package.xml /Image_Barcode/Barcode Code39.php ean13.php int25.php upca.php /Image_Barcode/docs Readme.txt
/Image_Barcode/docs/examples barcode_img.php test-image-barcode.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-32236@lists.php.net to get a copy of this message
msmarcal Mon May 30 00:31:42 2005 EDT Modified files: /pear/Image_Barcode Barcode.php package.xml /pear/Image_Barcode/Barcode Code39.php ean13.php int25.php upca.php /pear/Image_Barcode/docs Readme.txt /pear/Image_Barcode/docs/examples barcode_img.php test-image-barcode.php Log: - Added Code128 barcode rendering (thanks to Jeffrey K. Brown)

http://cvs.php.net/diff.php/pear/Image_Barcode/Barcode.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_Barcode/Barcode.php diff -u pear/Image_Barcode/Barcode.php:1.1 pear/Image_Barcode/Barcode.php:1.2 --- pear/Image_Barcode/Barcode.php:1.1 Wed May 25 11:32:35 2005 +++ pear/Image_Barcode/Barcode.php Mon May 30 00:31:40 2005 @@ -1,33 +1,42 @@ <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ -// -// +----------------------------------------------------------------------+ -// | PHP version 4.0 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2001 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | 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 world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Author: Marcelo Subtil Marcal <msmarcal@php.net> | -// +----------------------------------------------------------------------+ -// -// $Id: Barcode.php,v 1.1 2005/05/25 15:32:35 msmarcal Exp $ -// + +/** + * Image_Barcode class + * + * Package to render barcodes + * + * PHP versions 4 + * + * 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 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: Barcode.php,v 1.2 2005/05/30 04:31:40 msmarcal Exp $ + * @link http://pear.php.net/package/Image_Barcode + */ require_once("PEAR.php"); /** - * The Image_Barcode class provides method to create barcode using GD library. + * Image_Barcode class + * + * Package which provides a method to create barcode using GD library. * - * @access public - * @author Marcelo Subtil Marcal <msmarcal@php.net> - * @since PHP 4.2.3 + * @category Image + * @package Image_Barcode + * @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_Barcode */ class Image_Barcode extends PEAR { @@ -35,18 +44,39 @@ * Draws a image barcode * * @param string $text A text that should be in the image barcode - * @param string $type The barcode type + * @param string $type The barcode type. Supported types: + * Code39 - Code 3 of 9 + * int25 - 2 Interleaved 5 + * ean13 - EAN 13 + * upca - UPC-A * @param string $imgtype The image type that will be generated * * @return image The corresponding image barcode * * @access public + * * @author Marcelo Subtil Marcal <msmarcal@php.net> - * @since PHP 4.2.3 + * @since Image_Barcode 0.3 */ function draw($text, $type = 'int25', $imgtype = 'png') { - @include_once("Image/Barcode/${type}.php"); + // Check if include file exists + $barcodepath = PEAR_INSTALL_DIR . DIRECTORY_SEPARATOR . "Image" . DIRECTORY_SEPARATOR . "Barcode"; + $supportedtypes = array(); + if ( $incdir = opendir($barcodepath) ) { + while ( false != ( $avaiabletype = readdir($incdir) ) ) { + if ( strstr($avaiabletype, ".php") ) { + $supportedtypes[] = $avaiabletype; + } + } + closedir($incdir); + } + + if ( in_array($type . ".php", $supportedtypes) ) { + include_once("Image/Barcode/${type}.php"); + } else { + return PEAR::raiseError("$type barcode is not supported"); + } $classname = "Image_Barcode_${type}"; http://cvs.php.net/diff.php/pear/Image_Barcode/package.xml?r1=1.2&r2=1.3&ty=u Index: pear/Image_Barcode/package.xml diff -u pear/Image_Barcode/package.xml:1.2 pear/Image_Barcode/package.xml:1.3 --- pear/Image_Barcode/package.xml:1.2 Wed May 25 12:13:46 2005 +++ pear/Image_Barcode/package.xml Mon May 30 00:31:40 2005 @@ -18,29 +18,48 @@ </maintainers> <release> - <version>1.0.2</version> - <date>2005-05-24</date> + <version>1.0.3</version> + <date>2005-05-30</date> <license>PHP License</license> <state>stable</state> <notes> - - Added UPC-A barcode rendering (thanks to Jeffrey K. Brown) - </notes> + - Added Code128 barcode rendering (thanks to Jeffrey K. Brown) + </notes> <filelist> - <file role="php" baseinstalldir="Image" name="Barcode.php"/> - <file role="php" baseinstalldir="Image" name="Barcode/int25.php"/> - <file role="php" baseinstalldir="Image" name="Barcode/ean13.php"/> - <file role="php" baseinstalldir="Image" name="Barcode/Code39.php"/> - <file role="php" baseinstalldir="Image" name="Barcode/upca.php" /> - <file role="test" baseinstalldir="Image" name="docs/examples/test-image-barcode.php"/> - <file role="test" baseinstalldir="Image" name="docs/examples/barcode_img.php"/> - <file role="doc" baseinstalldir="Image" name="docs/ChangeLog"/> - <file role="doc" baseinstalldir="Image" name="docs/Readme.txt"/> + <dir name="/" baseinstalldir="Image"> + <file role="php">Barcode.php</file> + <dir name="Barcode" role="php"> + <file>int25.php</file> + <file>ean13.php</file> + <file>Code39.php</file> + <file>upca.php</file> + <file>code128.php</file> + </dir> + <dir name="docs" role="doc"> + <file>ChangeLog</file> + <file>Readme.txt</file> + <dir name="examples" role="doc"> + <file role="php">test-image-barcode.php</file> + <file role="php">barcode_img.php</file> + </dir> + </dir> + </dir> </filelist> </release> + <changelog> + <release> + <version>1.0.2</version> + <date>2005-05-24</date> + <license>PHP License</license> + <state>stable</state> + <notes>- Added UPC-A barcode rendering (thanks to Jeffrey K. Brown)</notes> + </release> + </changelog> + <deps> <dep type="pkg" rel="has" optional="yes">PHP_Compat</dep> - <dep type="ext" rel="has">gd</dep> + <dep type="ext" rel="has">gd</dep> </deps> - + </package> http://cvs.php.net/diff.php/pear/Image_Barcode/Barcode/Code39.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_Barcode/Barcode/Code39.php diff -u pear/Image_Barcode/Barcode/Code39.php:1.1 pear/Image_Barcode/Barcode/Code39.php:1.2 --- pear/Image_Barcode/Barcode/Code39.php:1.1 Wed May 25 11:31:09 2005 +++ pear/Image_Barcode/Barcode/Code39.php Mon May 30 00:31:41 2005 @@ -1,148 +1,144 @@ <?php -/* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | PHP version 4 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2003 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 2.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available through the world-wide-web at | -// | http://www.php.net/license/2_02.txt. | -// | If you did not receive a copy of the PHP license and are unable to | -// | obtain it through the world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Authors: Ryan Briones <ryanbriones@webxdesign.org> | -// | | -// +----------------------------------------------------------------------+ -// -// Last Modified: 2003/12/09 - Ryan Briones +/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ /** + * Image_Barcode_Code39 class * * Image_Barcode_Code39 creates Code 3 of 9 ( Code39 ) barcode images. It's * implementation borrows heavily for the perl module GD::Barcode::Code39 * - * @author Ryan Briones <ryanbriones@webxdesign.org> - * @todo add a function to print images directly to browser not using the draw() function + * PHP versions 4 * + * 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 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: Code39.php,v 1.2 2005/05/30 04:31:41 msmarcal Exp $ + * @link http://pear.php.net/package/Image_Barcode */ require_once "PEAR.php"; require_once "Image/Barcode.php"; -/* + +if ( !function_exists('str_split') ) { + require_once "PHP/Compat.php"; + PHP_Compat::loadFunction('str_split'); +} + +/** + * Image_Barcode_Code39 class * - * the function str_split() has been including, not part of the class for - * it's ability to emulate Perl's split( //, $text ). This function was - * stolen from the PHP function documentation comments on PHP's str_split() - * which is to be included in PHP5. + * Package which provides a method to create Code39 using GD library. * - * @param string $str - * @param int number of characters you wish to split on - * @return array|false Returns an array or false when $num is less than 1 + * @category Image + * @package Image_Barcode + * @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_Barcode + * @since Image_Barcode 0.5 */ -function str_split( $str, $num = '1' ) { - if($num < 1) return FALSE; - $arr = array(); - for ($j = 0; $j < strlen($str); $j= $j+$num) { - $arr[] = substr($str,$j,$num); - } - return $arr; -} - class Image_Barcode_Code39 extends Image_Barcode { - /** - * Barcode type - * @var string - */ - var $_type = 'Code39'; - - /** - * Barcode height - * - * @var integer - */ - var $_barcodeheight = 50; - - /** - * Bar thin width - * - * @var integer - */ - var $_barthinwidth = 1; - - /** - * Bar thick width - * - * @var integer - */ - var $_barthickwidth = 3; - - /** - * 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' - ); - - /* - * - * constructor - * - * @param string $text - * @param int $wThin Width of the thin lines on the barcode - * @param int $wThick Width of the thick lines on the barcode - * - */ + /** + * Barcode type + * @var string + */ + var $_type = 'Code39'; + + /** + * Barcode height + * + * @var integer + */ + var $_barcodeheight = 50; + + /** + * Bar thin width + * + * @var integer + */ + var $_barthinwidth = 1; + + /** + * Bar thick width + * + * @var integer + */ + var $_barthickwidth = 3; + + /** + * 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' + ); + + /** + * Constructor + * + * @param string $text A text that should be in the image barcode + * @param int $wThin Width of the thin lines on the barcode + * @param int $wThick Width of the thick lines on the barcode + * + * @author Ryan Briones <ryanbriones@webxdesign.org> + * + */ function Image_Barcode_Code39( $text = '', $wThin = 0, $wThick = 0 ) { - + // Check $text for invalid characters if ( $this->checkInvalid( $text ) ) { return false; @@ -154,34 +150,35 @@ return true; } - - /* - * - * make an image resource using the GD image library - * - * @param bool $noText Set to true if you'd like your barcode to be sans text - * @param int $bHeight height of the barcode image including text - * @return resource The Barcode Image (TM) - * - */ + + /** + * Make an image resource using the GD image library + * + * @param bool $noText Set to true if you'd like your barcode to be sans text + * @param int $bHeight height of the barcode image including text + * @return resource The Barcode Image (TM) + * + * @author Ryan Briones <ryanbriones@webxdesign.org> + * + */ function plot( $noText = false, $bHeight = 0 ) { // add start and stop * characters $final_text = "*" . $this->text . "*"; - - if ( $bHeight > 0 ) { - $this->_barcodeheight = $bHeight; - } - + + if ( $bHeight > 0 ) { + $this->_barcodeheight = $bHeight; + } + $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 = imagecreate( $barcode_len, $this->_barcodeheight ); - + // Allocate black and white colors to the image $black = imagecolorallocate( $img, 0, 0, 0 ); $white = imagecolorallocate( $img, 255, 255, 255 ); @@ -193,120 +190,124 @@ // Initialize X position $xpos = 0; - + // draw barcode bars to image - if ( $noText ) { - foreach ( str_split( $barcode ) as $character_code ) { - if ( $character_code == 0 ) { - imageline( $img, $xpos, 0, $xpos, $this->_barcodeheight, $white ); - } else { - imageline( $img, $xpos, 0, $xpos, $this->_barcodeheight, $black ); - } - - $xpos++; - } - } else { - foreach ( str_split( $barcode ) as $character_code ) { - if ( $character_code == 0 ) { - imageline( $img, $xpos, 0, $xpos, $this->_barcodeheight - $font_height - 1, $white ); - } else { - imageline( $img, $xpos, 0, $xpos, $this->_barcodeheight - $font_height - 1, $black ); - } - - $xpos++; - } - - // draw text under barcode - imagestring( $img, "gdFontSmall", - ( $barcode_len - $font_width * strlen( $this->text ) )/2, - $this->_barcodeheight - $font_height, - $this->text, - $black ); - } + if ( $noText ) { + foreach ( str_split( $barcode ) as $character_code ) { + if ( $character_code == 0 ) { + imageline( $img, $xpos, 0, $xpos, $this->_barcodeheight, $white ); + } else { + imageline( $img, $xpos, 0, $xpos, $this->_barcodeheight, $black ); + } + + $xpos++; + } + } else { + foreach ( str_split( $barcode ) as $character_code ) { + if ( $character_code == 0 ) { + imageline( $img, $xpos, 0, $xpos, $this->_barcodeheight - $font_height - 1, $white ); + } else { + imageline( $img, $xpos, 0, $xpos, $this->_barcodeheight - $font_height - 1, $black ); + } + + $xpos++; + } + + // draw text under barcode + imagestring( $img, "gdFontSmall", + ( $barcode_len - $font_width * strlen( $this->text ) )/2, + $this->_barcodeheight - $font_height, + $this->text, + $black ); + } return $img; } - /* - * - * send image to the browser; for Image_Barcode compaitbility - * - * @param string $text - * @param string $imgtype Image type; accepts jpg, png, and gif, but gif only works if you've payed for licensing - * @param bool $noText Set to true if you'd like your barcode to be sans text - * @param int $bHeight height of the barcode image including text - * @return bool true or die - * - */ + /** + * Send image to the browser; for Image_Barcode compaitbility + * + * @param string $text + * @param string $imgtype Image type; accepts jpg, png, and gif, but gif only works if you've payed for licensing + * @param bool $noText Set to true if you'd like your barcode to be sans text + * @param int $bHeight height of the barcode image including text + * @return bool true or die + * + * @author Ryan Briones <ryanbriones@webxdesign.org> + * + */ function draw( $text, $imgtype = 'png', $noText = false, $bHeight = 0 ) { - // Check $text for invalid characters + // Check $text for invalid characters if ( $this->checkInvalid( $text ) ) { return false; } - - $this->text = $text; + + $this->text = $text; $img = $this->plot( $noText, $bHeight ); - // Send image to browser - switch($imgtype) { - case 'gif': - header("Content-type: image/gif"); - imagegif($img); - imagedestroy($img); - break; - - case 'jpg': - header("Content-type: image/jpg"); - imagejpeg($img); - imagedestroy($img); - break; - - default: - header("Content-type: image/png"); - imagepng($img); - imagedestroy($img); - break; - } - - return true; + // Send image to browser + switch($imgtype) { + case 'gif': + header("Content-type: image/gif"); + imagegif($img); + imagedestroy($img); + break; + + case 'jpg': + header("Content-type: image/jpg"); + imagejpeg($img); + imagedestroy($img); + break; + + default: + header("Content-type: image/png"); + imagepng($img); + imagedestroy($img); + break; + } + + return true; } - /* - * + /** * _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 + * @param string $code Code39 barcode code + * @return string $result barcode line code + * + * @access private + * + * @author Ryan Briones <ryanbriones@webxdesign.org> + * * */ - 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 ) { - $result .= ( ( $bit == 1 ) ? str_repeat( "$color", $this->_barthickwidth ) : str_repeat( "$color", $this->_barthinwidth ) ); - $color = ( ( $color == 0 ) ? 1 : 0 ); - } - - return $result; - } - - /* - * - * check for invalid characters - * - * @param string $text - * @return bool returns true when invalid characters have been found - * - */ - function checkInvalid( $text ) { - return preg_match( "/[^0-9A-Z\-*+\$%\/. ]/", $text ); - } + 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 ) { + $result .= ( ( $bit == 1 ) ? str_repeat( "$color", $this->_barthickwidth ) : str_repeat( "$color", $this->_barthinwidth ) ); + $color = ( ( $color == 0 ) ? 1 : 0 ); + } + + return $result; + } + + /** + * Check for invalid characters + * + * @param string $text text to be ckecked + * @return bool returns true when invalid characters have been found + * + * @author Ryan Briones <ryanbriones@webxdesign.org> + * + */ + function checkInvalid( $text ) { + return preg_match( "/[^0-9A-Z\-*+\$%\/. ]/", $text ); + } } ?> http://cvs.php.net/diff.php/pear/Image_Barcode/Barcode/ean13.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_Barcode/Barcode/ean13.php diff -u pear/Image_Barcode/Barcode/ean13.php:1.1 pear/Image_Barcode/Barcode/ean13.php:1.2 --- pear/Image_Barcode/Barcode/ean13.php:1.1 Wed May 25 11:31:09 2005 +++ pear/Image_Barcode/Barcode/ean13.php Mon May 30 00:31:41 2005 @@ -1,34 +1,45 @@ <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ -// -// +----------------------------------------------------------------------+ -// | PHP version 4.0 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2001 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | 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 world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Author: Didier FOURNOUT <didier.fournout@nyc.fr> | -// +----------------------------------------------------------------------+ -// -// $Id: ean13.php,v 1.1 2005/05/25 15:31:09 msmarcal Exp $ -// + +/** + * Image_Barcode_ean13 class + * + * Renders EAN 13 barcodes + * + * PHP versions 4 + * + * 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: ean13.php,v 1.2 2005/05/30 04:31:41 msmarcal Exp $ + * @link http://pear.php.net/package/Image_Barcode + */ require_once "PEAR.php"; require_once "Image/Barcode.php"; /** - * Class to create a EAN 13 barcode + * Image_Barcode_ean13 class * - * @author Didier FOURNOUT <didier.fournout@nyc.fr> + * Package which provides a method to create EAN 13 barcode using GD library. + * + * @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 Release: @package_version@ + * @link http://pear.php.net/package/Image_Barcode + * @since Image_Barcode 0.4 */ - class Image_Barcode_ean13 extends Image_Barcode { /** @@ -128,6 +139,20 @@ '8' => array('A','B','A','B','B','A'), '9' => array('A','B','B','A','B','A') ); + + /** + * Draws a EAN 13 image barcode + * + * @param string $text A text that should be in the image barcode + * @param string $imgtype The image type that will be generated + * + * @return image The corresponding Interleaved 2 of 5 image barcode + * + * @access public + * + * @author Didier Fournout <didier.fournout@nyc.fr> + * + */ function draw($text, $imgtype = 'png') { //TODO: Check if $text is number and len=13 @@ -249,4 +274,4 @@ } // function create -} // class \ No newline at end of file +} // class http://cvs.php.net/diff.php/pear/Image_Barcode/Barcode/int25.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_Barcode/Barcode/int25.php diff -u pear/Image_Barcode/Barcode/int25.php:1.1 pear/Image_Barcode/Barcode/int25.php:1.2 --- pear/Image_Barcode/Barcode/int25.php:1.1 Wed May 25 11:31:09 2005 +++ pear/Image_Barcode/Barcode/int25.php Mon May 30 00:31:41 2005 @@ -1,34 +1,45 @@ <?php /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ -// -// +----------------------------------------------------------------------+ -// | PHP version 4.0 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2001 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | 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 world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Author: Marcelo Subtil Marcal <msmarcal@php.net> | -// +----------------------------------------------------------------------+ -// -// $Id: int25.php,v 1.1 2005/05/25 15:31:09 msmarcal Exp $ -// + +/** + * Image_Barcode_int25 class + * + * Renders Interleaved 2 of 5 barcodes + * + * PHP versions 4 + * + * 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 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: int25.php,v 1.2 2005/05/30 04:31:41 msmarcal Exp $ + * @link http://pear.php.net/package/Image_Barcode + */ require_once "PEAR.php"; require_once "Image/Barcode.php"; + /** - * Class to create a Interleaved 2 of 5 barcode + * Image_Barcode_int25 class + * + * Package which provides a method to create Interleaved 2 of 5 barcode using GD library. * - * @author Marcelo Subtil Marcal <msmarcal@php.net> + * @category Image + * @package Image_Barcode + * @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_Barcode */ - class Image_Barcode_int25 extends Image_Barcode { /** @@ -75,6 +86,20 @@ '9' => '01010' ); + /** + * Draws a Interleaved 2 of 5 image barcode + * + * @param string $text A text that should be in the image barcode + * @param string $imgtype The image type that will be generated + * + * @return image The corresponding Interleaved 2 of 5 image barcode + * + * @access public + * + * @author Marcelo Subtil Marcal <msmarcal@php.net> + * @since Image_Barcode 0.3 + */ + function draw($text, $imgtype = 'png') { http://cvs.php.net/diff.php/pear/Image_Barcode/Barcode/upca.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_Barcode/Barcode/upca.php diff -u pear/Image_Barcode/Barcode/upca.php:1.1 pear/Image_Barcode/Barcode/upca.php:1.2 --- pear/Image_Barcode/Barcode/upca.php:1.1 Wed May 25 11:31:09 2005 +++ pear/Image_Barcode/Barcode/upca.php Mon May 30 00:31:41 2005 @@ -1,345 +1,358 @@ -<?php -/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ -// -// +----------------------------------------------------------------------+ -// | PHP version 4.0 | -// +----------------------------------------------------------------------+ -// | Copyright (c) 1997-2001 The PHP Group | -// +----------------------------------------------------------------------+ -// | This source file is subject to version 3.0 of the PHP license, | -// | that is bundled with this package in the file LICENSE, and is | -// | available at through the world-wide-web at | -// | 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 world-wide-web, please send a note to | -// | license@php.net so we can mail you a copy immediately. | -// +----------------------------------------------------------------------+ -// | Author: Didier FOURNOUT <didier.fournout@nyc.fr> | -// +----------------------------------------------------------------------+ -// -// $Id: upca.php,v 1.1 2005/05/25 15:31:09 msmarcal Exp $ -// -// +----------------------------------------------------------+ -// Jeffrey K. Brown 5/22/2005 -// Slightly Modified ean13.php to get upca.php -// I needed a way to print UPC-A bar codes on a -// PHP page. The Image_Barcode 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 -// +----------------------------------------------------------+ - -require_once "PEAR.php"; -require_once "Image/Barcode.php"; - -class Image_Barcode_upca extends Image_Barcode -{ - /** - * Barcode type - * @var string - */ - var $_type = 'upca'; - - /** - * Barcode height - * - * @var integer - */ - var $_barcodeheight = 50; - - /** - * Font use to display text - * - * @var integer - */ - var $_font = 2; // gd internal small font - - /** - * Bar width - * - * @var integer - */ - var $_barwidth = 1; - - - /** - * 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') - ); - - - - -//========================================================================================== - -function draw($text, $imgtype = 'png') { - - if ( (is_numeric($text)==false) || (strlen($text)!=12) ) { - $barcodewidth= (12 * 7 * $this->_barwidth) + 3 + 5 + 3 + 2 * (imagefontwidth($this->_font)+1); - $error = 1; - } - else { - // Calculate the barcode width - $barcodewidth = (strlen($text)) * (7 * $this->_barwidth) - + 3 // left - + 5 // center - + 3 // right - + imagefontwidth($this->_font)+1 - + imagefontwidth($this->_font)+1 // check digit's padding - ; - } - - $barcodelongheight = (int) (imagefontheight($this->_font)/2)+$this->_barcodeheight; - - // Create the image - $img = ImageCreate($barcodewidth, $barcodelongheight+ imagefontheight($this->_font)+1); - - // Alocate the black and white colors - $black = ImageColorAllocate($img, 0, 0, 0); - $white = ImageColorAllocate($img, 255, 255, 255); - - // Fill image with white color - imagefill($img, 0, 0, $white); - - if ($error==1) { - $imgerror = ImageCreate($barcodewidth, $barcodelongheight+imagefontheight($this->_font)+1); - $red = ImageColorAllocate($imgerror, 255, 0, 0); - $black = ImageColorAllocate($imgerror, 0,0,0); - imagefill($imgerror,0,0,$red); - - imagestring($imgerror, $this->_font, $barcodewidth/2-(10/2* imagefontwidth($this->_font)), $this->_barcodeheight/2, "Code Error", $black); - } - - // 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 - imagestring($img, $this->_font, $xpos, $this->_barcodeheight, $key, $black); - $xpos= imagefontwidth($this->_font) + 1; - - -//=========================================================================================== - - - // Draws the left guard pattern (bar-space-bar) - // bar - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); - $xpos += $this->_barwidth; - // space - $xpos += $this->_barwidth; - // bar - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); - $xpos += $this->_barwidth; - - $set_array = $this->_number_set_left_coding[$key]; - - -//========================================================================================= - - - foreach ($this->_number_set['0'][$set_array[0]] as $bar) { - if ($bar) { - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); - } - $xpos += $this->_barwidth; - } - - -//========================================================================================= - - // Draw left $text contents - for ($idx = 1; $idx < 6; $idx ++) { - $value=substr($text,$idx,1); - imagestring ($img, $this->_font, $xpos+1, $this->_barcodeheight, $value, $black); - - //foreach ($this->_number_set[$value][$set_array[$idx-1]] as $bar) { - - foreach ($this->_number_set[$value][$set_array[$idx]] as $bar) { - if ($bar) { - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $this->_barcodeheight, $black); - } - $xpos += $this->_barwidth; - } - } - -//========================================================================================= - - // Draws the center pattern (space-bar-space-bar-space) - // space - $xpos += $this->_barwidth; - // bar - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); - $xpos += $this->_barwidth; - // space - $xpos += $this->_barwidth; - // bar - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); - $xpos += $this->_barwidth; - // space - $xpos += $this->_barwidth; - -//==================================================================================== - - // Draw right $text contents - for ($idx = 6; $idx < 11; $idx ++) { - $value=substr($text,$idx,1); - imagestring ($img, $this->_font, $xpos+1, $this->_barcodeheight, $value, $black); - foreach ($this->_number_set[$value]['C'] as $bar) { - if ($bar) { - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $this->_barcodeheight, $black); - } - $xpos += $this->_barwidth; - } - } - - -//====================================================================================== - - $value = substr($text,11,1); - foreach ($this->_number_set[$value]['C'] as $bar) { - if ($bar) { - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); - } - $xpos += $this->_barwidth; - } - - -// =================================================================================== - - // Draws the right guard pattern (bar-space-bar) - // bar - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); - $xpos += $this->_barwidth; - // space - $xpos += $this->_barwidth; - // bar - imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); - $xpos += $this->_barwidth; - -// ==================================================================================== - - // Print Check Digit - imagestring($img, $this->_font, $xpos+1, $this->_barcodeheight, $value, $black); - - -// ====================================================================================== - - // Send image to browser - switch($imgtype) { - - case 'gif': - header("Content-type: image/gif"); - - if ($error==1) { - imagegif($imgerror); - imagedestroy($imgerror); - } - else { - imagegif($img); - imagedestroy($img); - } - break; - - case 'jpg': - header("Content-type: image/jpg"); - if ($error==1) { - imageijpeg($imgerror); - imagedestroy($imgerror); - } - else { - imagejpeg($img); - imagedestroy($img); - } - break; - - default: - header("Content-type: image/png"); - if ($error==1) { - imagepng($imgerror); - imagedestroy($imgerror); - } - else { - imagepng($img); - imagedestroy($img); - } - break; - - } - - return; - - } // function create - -} // class +<?php +/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */ + +/** + * Image_Barcode_upca class + * + * Renders UPC-A barcodes + * + * PHP versions 4 + * + * 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 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: upca.php,v 1.2 2005/05/30 04:31:41 msmarcal Exp $ + * @link http://pear.php.net/package/Image_Barcode + */ + +require_once "PEAR.php"; +require_once "Image/Barcode.php"; + +/** + * Image_Barcode_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_Barcode 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_Barcode + * @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_Barcode + */ +class Image_Barcode_upca extends Image_Barcode +{ + /** + * Barcode type + * @var string + */ + var $_type = 'upca'; + + /** + * Barcode height + * + * @var integer + */ + var $_barcodeheight = 50; + + /** + * Font use to display text + * + * @var integer + */ + var $_font = 2; // gd internal small font + + /** + * Bar width + * + * @var integer + */ + var $_barwidth = 1; + + + /** + * 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') + ); + + + + /** + * Draws a UPC-A image barcode + * + * @param string $text A text that should be in the image barcode + * @param string $imgtype The image type that will be generated + * + * @return image The corresponding Interleaved 2 of 5 image barcode + * + * @access public + * + * @author Jeffrey K. Brown <jkb@darkfantastic.net> + * @author Didier Fournout <didier.fournout@nyc.fr> + * + */ + function draw($text, $imgtype = 'png') { + + if ( (is_numeric($text)==false) || (strlen($text)!=12) ) { + $barcodewidth= (12 * 7 * $this->_barwidth) + 3 + 5 + 3 + 2 * (imagefontwidth($this->_font)+1); + $error = 1; + } + else { + // Calculate the barcode width + $barcodewidth = (strlen($text)) * (7 * $this->_barwidth) + + 3 // left + + 5 // center + + 3 // right + + imagefontwidth($this->_font)+1 + + imagefontwidth($this->_font)+1 // check digit's padding + ; + } + + $barcodelongheight = (int) (imagefontheight($this->_font)/2)+$this->_barcodeheight; + + // Create the image + $img = ImageCreate($barcodewidth, $barcodelongheight+ imagefontheight($this->_font)+1); + + // Alocate the black and white colors + $black = ImageColorAllocate($img, 0, 0, 0); + $white = ImageColorAllocate($img, 255, 255, 255); + + // Fill image with white color + imagefill($img, 0, 0, $white); + + if ($error == 1) { + $imgerror = ImageCreate($barcodewidth, $barcodelongheight+imagefontheight($this->_font)+1); + $red = ImageColorAllocate($imgerror, 255, 0, 0); + $black = ImageColorAllocate($imgerror, 0,0,0); + imagefill($imgerror,0,0,$red); + + imagestring($imgerror, $this->_font, $barcodewidth/2-(10/2* imagefontwidth($this->_font)), $this->_barcodeheight/2, "Code Error", $black); + } + + // 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 + imagestring($img, $this->_font, $xpos, $this->_barcodeheight, $key, $black); + $xpos= imagefontwidth($this->_font) + 1; + + + + // Draws the left guard pattern (bar-space-bar) + // bar + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); + $xpos += $this->_barwidth; + // space + $xpos += $this->_barwidth; + // bar + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); + $xpos += $this->_barwidth; + + $set_array = $this->_number_set_left_coding[$key]; + + + + foreach ($this->_number_set['0'][$set_array[0]] as $bar) { + if ($bar) { + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); + } + $xpos += $this->_barwidth; + } + + + + // Draw left $text contents + for ($idx = 1; $idx < 6; $idx ++) { + $value=substr($text,$idx,1); + imagestring ($img, $this->_font, $xpos+1, $this->_barcodeheight, $value, $black); + + //foreach ($this->_number_set[$value][$set_array[$idx-1]] as $bar) { + + foreach ($this->_number_set[$value][$set_array[$idx]] as $bar) { + if ($bar) { + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $this->_barcodeheight, $black); + } + $xpos += $this->_barwidth; + } + } + + + // Draws the center pattern (space-bar-space-bar-space) + // space + $xpos += $this->_barwidth; + // bar + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); + $xpos += $this->_barwidth; + // space + $xpos += $this->_barwidth; + // bar + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); + $xpos += $this->_barwidth; + // space + $xpos += $this->_barwidth; + + + // Draw right $text contents + for ($idx = 6; $idx < 11; $idx ++) { + $value=substr($text,$idx,1); + imagestring ($img, $this->_font, $xpos+1, $this->_barcodeheight, $value, $black); + foreach ($this->_number_set[$value]['C'] as $bar) { + if ($bar) { + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $this->_barcodeheight, $black); + } + $xpos += $this->_barwidth; + } + } + + + + $value = substr($text,11,1); + foreach ($this->_number_set[$value]['C'] as $bar) { + if ($bar) { + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); + } + $xpos += $this->_barwidth; + } + + + + // Draws the right guard pattern (bar-space-bar) + // bar + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); + $xpos += $this->_barwidth; + // space + $xpos += $this->_barwidth; + // bar + imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); + $xpos += $this->_barwidth; + + + // Print Check Digit + imagestring($img, $this->_font, $xpos+1, $this->_barcodeheight, $value, $black); + + + + // Send image to browser + switch($imgtype) { + + case 'gif': + header("Content-type: image/gif"); + + if ($error==1) { + imagegif($imgerror); + imagedestroy($imgerror); + } + else { + imagegif($img); + imagedestroy($img); + } + break; + + case 'jpg': + header("Content-type: image/jpg"); + if ($error==1) { + imageijpeg($imgerror); + imagedestroy($imgerror); + } + else { + imagejpeg($img); + imagedestroy($img); + } + break; + + default: + header("Content-type: image/png"); + if ($error==1) { + imagepng($imgerror); + imagedestroy($imgerror); + } + else { + imagepng($img); + imagedestroy($img); + } + break; + + } + + return; + + } // function create + +} // class http://cvs.php.net/diff.php/pear/Image_Barcode/docs/Readme.txt?r1=1.1&r2=1.2&ty=u Index: pear/Image_Barcode/docs/Readme.txt diff -u pear/Image_Barcode/docs/Readme.txt:1.1 pear/Image_Barcode/docs/Readme.txt:1.2 --- pear/Image_Barcode/docs/Readme.txt:1.1 Wed May 25 12:13:47 2005 +++ pear/Image_Barcode/docs/Readme.txt Mon May 30 00:31:41 2005 @@ -41,7 +41,7 @@ ----------------- You can get the latest code at the PEAR site: - http://pear.php.net/package-info.php?package=Image_Barcode + http://pear.php.net/package/Image_Barcode/ = Contributing = @@ -66,7 +66,7 @@ Code39 barcode module type written by Ryan Briones <ryanbriones@webxdesign.org> -UPC-A barcode module type +UPC-A and Code128 barcode modules written by Jeffrey K. Brown <jkb@darkfantastic.net> @@ -85,4 +85,4 @@ = Reporting Bugs = ------------------ -Report bugs to Marcelo Subtil Marcal <msmarcal@php.net> +Report bugs at: http://pear.php.net/bugs/report.php?package=Image_Barcode http://cvs.php.net/diff.php/pear/Image_Barcode/docs/examples/barcode_img.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_Barcode/docs/examples/barcode_img.php diff -u pear/Image_Barcode/docs/examples/barcode_img.php:1.1 pear/Image_Barcode/docs/examples/barcode_img.php:1.2 --- pear/Image_Barcode/docs/examples/barcode_img.php:1.1 Wed May 25 12:13:47 2005 +++ pear/Image_Barcode/docs/examples/barcode_img.php Mon May 30 00:31:41 2005 @@ -2,15 +2,10 @@ require_once("Image/Barcode.php"); -$num = '15101967'; -$type = 'int25'; -$imgtype = 'png'; - -$num = isset($_REQUEST) && is_array($_REQUEST) && isset($_REQUEST['num']) ? $_REQUEST['num'] : $num; -$type = isset($_REQUEST) && is_array($_REQUEST) && isset($_REQUEST['type']) ? $_REQUEST['type'] : $type; -$imgtype = isset($_REQUEST) && is_array($_REQUEST) && isset($_REQUEST['imgtype']) ? $_REQUEST['imgtype'] : $imgtype; +$num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '15101967'; +$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'int25'; +$imgtype = isset($_REQUEST['imgtype']) ? $_REQUEST['imgtype'] : 'png'; Image_Barcode::draw($num, $type, $imgtype); - ?> http://cvs.php.net/diff.php/pear/Image_Barcode/docs/examples/test-image-barcode.php?r1=1.1&r2=1.2&ty=u Index: pear/Image_Barcode/docs/examples/test-image-barcode.php diff -u pear/Image_Barcode/docs/examples/test-image-barcode.php:1.1 pear/Image_Barcode/docs/examples/test-image-barcode.php:1.2 --- pear/Image_Barcode/docs/examples/test-image-barcode.php:1.1 Wed May 25 12:13:47 2005 +++ pear/Image_Barcode/docs/examples/test-image-barcode.php Mon May 30 00:31:41 2005 @@ -1,31 +1,84 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> -<title>Image_Barcode Class Test</title> -<body background="#FFFFFF"> - -<h1>Image_Barcode Class test</h1> - + <title>Image_Barcode Class Test</title> + <style type="text/css"> + body { + font-family: Verdana; + font-size: 10pt; + } + h1 { + font-size: 14pt; + } + h2 { + font-size: 12pt; + } + .box { + border: 1px solid rgb(15, 169, 229) ! important; + margin: 10px ! important; + padding: 10px ! important; + font-size: 0.9em ! important; + font-weight: normal ! important; + text-decoration: none ! important; + line-height: 1.5em ! important; + color: rgb(0, 0, 0) ! important; + background-color: rgb(231, 244, 252) ! important; + white-space: normal ! important; + cursor: pointer ! important; + } + .test { + border: 1px solid; + margin: 10px ! important; + padding: 10px ! important; + } + </style> +</head> +<body style="background-image: url(#FFFFFF);"> <?php $num = "019671015005"; $num = isset($_REQUEST) && is_array($_REQUEST) && isset($_REQUEST['num']) ? $_REQUEST['num'] : $num; -echo "Test number: <b>$num</b>\n<p>\n"; - ?> +<div class="box"> +<h1>Image_Barcode Class test</h1> +Test number: <b><?php echo($num) ?></b> +</div> -Interleave 2 of 5 (png):<br> -<img src="barcode_img.php?num=<?php echo($num)?>&type=int25&imgtype=png" alt="PNG: <?php echo($num)?>" title="PNG: <?php echo($num)?>"> -<p> -Ean13 (png):<br> -<img src="barcode_img.php?num=<?php echo($num)?>&type=ean13&imgtype=png" alt="PNG: <?php echo($num)?>" title="PNG: <?php echo($num)?>"> -<p> -Code39 (png):<br> -<img src="barcode_img.php?num=<?php echo($num)?>&type=Code39&imgtype=png" alt="PNG: <?php echo($num)?>" title="PNG: <?php echo($num)?>"> -<p> -UPC-A (png):<br> -<img src="barcode_img.php?num=<?php echo($num)?>&type=upca&imgtype=png" alt="PNG: <?php echo($num)?>" title="PNG: <?php echo($num)?>"> +<div class="test"> +<h2>Interleave 2 of 5 (png):</h2> +<img src="barcode_img.php?num=<?php echo $num ?>&type=int25&imgtype=png" + alt="PNG: <?php echo($num)?>" title="PNG: <?php echo($num)?>"> +</div> + +<div class="test"> +<h2>Ean13 (png):</h2> +<img + src="barcode_img.php?num=<?php echo $num ?>&type=ean13&imgtype=png" + alt="PNG: <?php echo($num)?>" title="PNG: <?php echo($num)?>"> +</div> + +<div class="test"> +<h2>Code39 (png):</h2> +<img + src="barcode_img.php?num=<?php echo $num ?>&type=Code39&imgtype=png" + alt="PNG: <?php echo($num)?>" title="PNG: <?php echo($num)?>"> +</div> + +<div class="test"> +<h2>UPC-A (png):</h2> +<img + src="barcode_img.php?num=<?php echo $num ?>&type=upca&imgtype=png" + alt="PNG: <?php echo($num)?>" title="PNG: <?php echo($num)?>"> +</div> + +<div class="test"> +<h2>Code128 (png):</h2> +<img + src="barcode_img.php?num=<?php echo $num ?>&type=code128&imgtype=png" + alt="PNG: <?php echo($num)?>" title="PNG: <?php echo($num)?>"> +</div> </body> </html>
« previous php.pear.cvs (#32236) next »