1. Import

This commit is contained in:
2026-03-29 10:34:57 +02:00
parent b0e00c1259
commit a1129565af
4899 changed files with 3007593 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
You must modify the file config.php, change the following line to point to the /html/ folder with a real path
Vous devez modifier le fichier config.php, changez la ligne suivante pour qu'elle redirige vers le dossier /class/ avec le chemin complet
$class_dir = '../class';
change it for / changez le pour
$class_dir = 'C:/where/barcode_gen/is_installed/class';
Start with code39.php and you will be able to make barcodes
Commencez avec code39.php et vous serez capable de faire des codes barres

View File

@@ -0,0 +1,12 @@
This script is free for personal use. The program is provide "AS IS"
without warranty of any kind. If you want to use it as
commercial use, you have to purchase it on
http://www.barcodephp.com
You must let the copyright intact.
Ce script est gratuit pour usage personnel. Le programme est
fourni "TEL QUEL" sans aucune garantie que ce soit.
Si vous voulez l'utiliser pour un usage commercial,
vous devez l'acheter sur
http://www.barcodephp.com
Vous devez laisser le copyright intact.

View File

@@ -0,0 +1,72 @@
v2.2.0 13 feb 2010 Added the support for GS1-128 (EAN-128).
Fix ISBN text support to be the right font.
Make sure the /html files are formatted.
v2.1.0 8 nov 2009 Added a way to change the DPI before saving (BCGDrawing::setDPI()). Set the value to null if you want to improve the performance and still have 72dpi.
But you can set it to 300 if you wish to print it.
You do not need an additional DLL for this.
Added a way to rotate in degree the barcode before saving (BCGDrawing::setRotationAngle()).
Added a verification if you have GD installed... So that way you know it before contacting support :)
Fix HTML display for Code 93 and Code 39 Extended buttons
You can now specify a specific table for Code 128. For instance, if you want to force to use the table B, you would write the following to parse
array(CODE128_B, 'The Text To Encode')
The default table selection for Code 128 is automatically chosen.
Fix many PHP4 errors.
v2.0.1Fix 28 jul 2009 Change UPC-E encoding from UTF-8 to ANSI
v2.0.1 21 may 2009 Fix the Code 128C, Fix EAN-8, EAN-13, UPC-A, UPC-E and Postnet padding, MSI checksum can be 1 or 2
Fix JoinDraw class
Added GIF and WBMP support
Fix the Checksum Text displayed for ISBN
Fix padding for ISBN with setOffsetY
Fix Button in /html for IE8
v2.0.0 23 apr 2008 The new version has been released... All the codes have been revamped to fit with
common file for 2D barcodes. Instead of using "setText()" method, the method
parse() is used.
Thickness is modified by the scale.
Code 128: it has been modified completely, no need to specify which encoding you want to
use, it will select it for you automatically and try to get the shortest barcode.
Codabar: you can't only put one letter as a barcode.
Code 93: supports now the extended full ASCII 0 to 127
Code 39 extended has been added in a separate file since the extended
version of Code 39 is totally optional.
Codabar has been fixed for B and C letter
We got our real nice domain: http://www.barcodephp.com
v1.3.0 13 apr 2007 Remove ISBN from EAN-13 and a new file has been created to handle
ISBN-10 and ISBN-13.
v1.2.4 1 feb 2007 Fix Code128. There were some errors dealing with C table
v1.2.3pl1 11 mar 2006 Correct the EAN-13/ISBN file. There was a problem with displaying correctly an ISBN.
v1.2.3 8 feb 2006 Int for font is no longer deprecated and can be used.
Correct many labels' positions : ean8, ean13, upca, upce
Correct getWidth of Font.
v1.2.3b 5 jan 2006 Add separate checksum method to calculate and get this special number created and a way to display it with the label.
Correct code for PHP5.1 compatibility. Selecting a char by { } is now deprecated. Using of [ ] is used instead.
Correct checksum for Code11. In some case, the checksum was bad.
Correct problem displaying label with text under the baseline (letters such as p, g...).
SIZE_SPACING_FONT_END has been suppressed since the previous bug has been fixed.
Correct label if two barcode were generated with the same font. The font is now cloned immediately before using.
The FDrawing has new methods now, use setBarcode and draw instead of add_barcode and draw_all. Only one barcode per FDrawing is possible now.
Correct errors of othercode if no text font has been selected.
othercode was not working for PHP4 due to the lack of the str_split function. Now the function is emulated.
New file : JoinDraw allows you to join 2 graphic and align each of them. (Useful for UCPExt). PHP5 only
Currently Working on UPC-A label
v1.2.2 23 jul 2005 Correct checksum for i25 and s25 barcode (thanks to Gerald Pienkowski (Germany))
Enhance rapidity for some barcode
Change almost all comment in files : the update 1.2.1 was in 2005, not in 2004 ;)
v1.2.1 27 jun 2005 The php code is now cleaner :)
Increase rapidity of execution
Type verifications in conditions
NEW support of exterior font (Arial, Courier, etc.) with a size that you can specify
Use PHP fonts is deprecated and they will be deleted in further versions.
Remove the "alt" text on the image (IE displays it as a tooltip)
Color class has been enhanced and accept new parameter for constructor
Now you don't have to provide a specific size of the image, it will be calculated automatically for barcodes and errors
Added the version number at the bottom of the script html.
Correcting code 128 to output code correctly when passing from code C to another code
v1.05 27 jun 2005 UPCext2 has been corrected. It could display a wrong barcode.
Correcting UPC-A, bad output when writting text
v1.04 2 apr 2005 Correcting some bugs and makes available for commercial usage : purchase it on http://www.barcodephp.com
v1.03 28 mar 2005 Correcting DrawChar
v1.02 8 mar 2005 Transforming PHPDOC and converting to XHTML1.0 Transitionnal
And adding a special option that check if you have PHP5 installed
Because to many people are writing to me that saying the script doesn't work (because they have PHP4).
v1.01 7 jul 2004 Correcting code39.barcode.php
v1.00 17 jun 2004 New :)

View File

@@ -0,0 +1,218 @@
<?php
/**
* BCGBarcode.php
*--------------------------------------------------------------------
*
* Base class for Barcode 1D and 2D
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
*--------------------------------------------------------------------
* $Id: BCGBarcode.php,v 1.12 2010/02/14 00:25:14 jsgoupil Exp $
* PHP5-Revision: 1.13
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGColor.php');
class BCGBarcode { // abstract
var $COLOR_BG = 0; // const
var $COLOR_FG = 1; // const
var $error; // protected
var $colorFg, $colorBg; // Color Foreground, Barckground
var $scale; // Scale of the graphic, default: 1
var $offsetX, $offsetY; // Position where to start the drawing
function BCGBarcode() { // protected
$this->setForegroundColor(0x000000);
$this->setBackgroundColor(0xffffff);
$this->setScale(1);
$this->setOffsetX(0);
$this->setOffsetY(0);
$this->error = 0;
}
/**
* Parses the text before displaying it.
*
* @param mixed $text
*/
function parse($text) {} // public abstract
/**
* Sets the foreground color of the barcode. It could be a BCGColor
* value or simply a language code (white, black, yellow...) or hex value.
*
* @param mixed $code
*/
function setForegroundColor($code) {
if(is_a($code, 'BCGColor')) {
$this->colorFg =& $code;
} else {
$this->colorFg = new BCGColor($code);
}
}
/**
* Sets the background color of the barcode. It could be a BCGColor
* value or simply a language code (white, black, yellow...) or hex value.
*
* @param mixed $code
*/
function setBackgroundColor($code) {
if(is_a($code, 'BCGColor')) {
$this->colorBg =& $code;
} else {
$this->colorBg = new BCGColor($code);
}
}
/**
* Sets the color
*
* @param mixed $fg
* @param mixed $bg
*/
function setColor($fg, $bg) {
$this->setForegroundColor($fg);
$this->setBackgroundColor($bg);
}
function getScale() {
return $this->scale;
}
function setScale($scale) {
$scale = intval($scale);
if($scale <= 0) {
$scale = 1;
}
$this->scale = $scale;
}
function draw(&$im) {} // public abstract
/**
* Returns the maximal size of a barcode.
* [0]->width
* [1]->height
*
* @return int[]
*/
function getMaxSize() {
return array($this->offsetX * $this->scale, $this->offsetY * $this->scale);
}
/**
* Sets the X offset
*
* @param int $offsetX
*/
function setOffsetX($offsetX) {
$offsetX = intval($offsetX);
if($offsetX < 0) {
$offsetX = 0;
}
$this->offsetX = $offsetX;
}
/**
* Sets the Y offset
*
* @param int $offsetY
*/
function setOffsetY($offsetY) {
$offsetY = intval($offsetY);
if($offsetY < 0) {
$offsetY = 0;
}
$this->offsetY = $offsetY;
}
function drawPixel(&$im, $x, $y, $color = 1) { // protected
$xR = ($x + $this->offsetX) * $this->scale;
$yR = ($y + $this->offsetY) * $this->scale;
// we always draw a rectangle
imagefilledrectangle($im,
$xR,
$yR,
$xR + $this->scale - 1,
$yR + $this->scale - 1,
$this->getColor($im, $color));
}
function drawRectangle(&$im, $x1, $y1, $x2, $y2, $color = 1) { // protected
if($this->scale === 1) {
imagerectangle($im,
($x1 + $this->offsetX) * $this->scale,
($y1 + $this->offsetY) * $this->scale,
($x2 + $this->offsetX) * $this->scale,
($y2 + $this->offsetY) * $this->scale,
$this->getColor($im, $color));
} else {
imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale, ($y1 + $this->offsetY) * $this->scale, ($x2 + $this->offsetX) * $this->scale + $this->scale - 1, ($y1 + $this->offsetY) * $this->scale + $this->scale - 1, $this->getColor($im, $color));
imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale, ($y1 + $this->offsetY) * $this->scale, ($x1 + $this->offsetX) * $this->scale + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->scale - 1, $this->getColor($im, $color));
imagefilledrectangle($im, ($x2 + $this->offsetX) * $this->scale, ($y1 + $this->offsetY) * $this->scale, ($x2 + $this->offsetX) * $this->scale + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->scale - 1, $this->getColor($im, $color));
imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale, ($y2 + $this->offsetY) * $this->scale, ($x2 + $this->offsetX) * $this->scale + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->scale - 1, $this->getColor($im, $color));
}
}
function drawFilledRectangle(&$im, $x1, $y1, $x2, $y2, $color = 1) { // protected
if($x1 > $x2) { // Swap
$x1 ^= $x2 ^= $x1 ^= $x2;
}
if($y1 > $y2) { // Swap
$y1 ^= $y2 ^= $y1 ^= $y2;
}
imagefilledrectangle($im,
($x1 + $this->offsetX) * $this->scale,
($y1 + $this->offsetY) * $this->scale,
($x2 + $this->offsetX) * $this->scale + $this->scale - 1,
($y2 + $this->offsetY) * $this->scale + $this->scale - 1,
$this->getColor($im, $color));
}
function getColor(&$im, $color) { // protected
if($color === $this->COLOR_BG) {
return $this->colorBg->allocate($im);
} else {
return $this->colorFg->allocate($im);
}
}
/**
* Writes the Error on the picture
*
* @param ressource $img
* @param string $text
*/
function drawError(&$im, $text) { // protected
// Is the image big enough?
$w = imagesx($im);
$h = imagesy($im);
$text = 'Error: ' . $text;
$width = imagefontwidth(2) * strlen($text);
$height = imagefontheight(2) + $this->error * 15;
if($width > $w || $height > $h) {
$width = max($w, $width);
$height = max($h, $height);
// We change the size of the image
$newimg = imagecreatetruecolor($width, $height);
imagefill($newimg, 0, 0, imagecolorat($im, 0, 0));
imagecopy($newimg, $im, 0, 0, 0, 0, $w, $h);
$im = $newimg;
}
imagestring($im, 2, 0, $this->error * 15, $text, $this->colorFg->allocate($im));
$this->error++;
}
}
?>

View File

@@ -0,0 +1,226 @@
<?php
/**
* BCGBarcode1D.php
*--------------------------------------------------------------------
*
* Holds all type of barcodes for 1D generation
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
*--------------------------------------------------------------------
* $Id: BCGBarcode1D.php,v 1.3 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.3
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode.php');
include_once('BCGFont.php');
class BCGBarcode1D extends BCGBarcode { // abstract
var $SIZE_SPACING_FONT = 5; // const
var $AUTO_LABEL = '##!!AUTO_LABEL!!##'; // const
var $thickness;
var $keys, $code;
var $positionX;
var $textfont;
var $text, $label;
var $checksumValue;
var $displayChecksum;
function BCGBarcode1D() { // protected
BCGBarcode::BCGBarcode();
$this->setThickness(30);
$this->text = '';
$this->checksumValue = false;
$this->setLabel($this->AUTO_LABEL);
$this->setFont(5);
}
function setThickness($thickness) { // public
$this->thickness = $thickness;
}
function getThickness() { // public
return $this->thickness;
}
function parse($text) { // public
$this->text = $text;
$this->checksumValue = false; // Reset checksumValue
}
function setLabel($label) { // public
$this->label = $label;
}
function getLabel() { // public
$label = $this->label;
if($this->label === $this->AUTO_LABEL) {
$label = $this->text;
if($this->displayChecksum === true && ($checksum = $this->processChecksum()) !== false) {
$label .= $checksum;
}
}
return $label;
}
/**
* Saves the font.
*
* @param mixed $font BCGFont or int
*/
function setFont($font) { // public
if(is_a($font, 'BCGFont')) {
$this->textfont = $font; // clone
$this->textfont->setText($this->text);
} else {
$this->textfont = min(5, max(0, intval($font)));
}
}
function getMaxSize() { // public
$p = BCGBarcode::getMaxSize();
$label = $this->getLabel();
$textHeight = 0;
if(!empty($label)) {
if(is_a($this->textfont, 'BCGFont')) {
$textfont = $this->textfont; // clone
$textfont->setText($label);
$textHeight = $textfont->getHeight() + $this->SIZE_SPACING_FONT;
} elseif($this->textfont !== 0) {
$textHeight = imagefontheight($this->textfont) + $this->SIZE_SPACING_FONT;
}
}
return array($p[0], $p[1] + $this->thickness * $this->scale + $textHeight);
}
/**
* Gets the checksum of a Barcode.
* If no checksum is available, return FALSE.
*
* @return string
*/
function getChecksum() { // public
return $this->processChecksum();
}
/**
* Sets if the checksum is displayed with the label or not.
* The checksum must be activated in some case to make this variable effective.
*
* @param boolean $display
*/
function setDisplayChecksum($display) { // public
$this->displayChecksum = (bool)$display;
}
/**
* Returns the index in $keys (useful for checksum)
*
* @param mixed $var
* @return mixed
*/
function findIndex($var) { // protected
return array_search($var, $this->keys);
}
/**
* Returns the code of the char (useful for drawing bars)
*
* @param mixed $var
* @return string
*/
function findCode($var) { // protected
return $this->code[$this->findIndex($var)];
}
/**
* Draws all chars thanks to $code. if $start is true, the line begins by a space.
* if $start is false, the line begins by a bar.
*
* @param resource $im
* @param string $code
* @param boolean $start
*/
function drawChar(&$im, $code, $startBar = true) { // protected
$colors = array($this->COLOR_FG, $this->COLOR_BG);
$currentColor = $startBar ? 0 : 1;
$c = strlen($code);
for($i = 0; $i < $c; $i++) {
for($j = 0; $j < intval($code[$i]) + 1; $j++) {
$this->drawSingleBar($im, $colors[$currentColor]);
$this->nextX();
}
$currentColor = ($currentColor + 1) % 2;
}
}
/**
* Draws a Bar of $color depending of the resolution
*
* @param resource $img
* @param FColor $color
*/
function drawSingleBar(&$im, $color) { // protected
$this->drawFilledRectangle($im, $this->positionX, 0, $this->positionX, $this->thickness - 1, $color);
}
/**
* Moving the pointer right to write a bar
*/
function nextX() { // protected
$this->positionX++;
}
/**
* Draws the label under the barcode
*
* @param resource $im
*/
function drawText(&$im) { // protected
$label = $this->getLabel();
if(!empty($label)) {
$pA = $this->getMaxSize();
$pB = BCGBarcode1D::getMaxSize();
$w = $pA[0] - $pB[0];
if(is_a($this->textfont, 'BCGFont')) {
$textfont = $this->textfont; // clone
$textfont->setText($label);
$xPosition = ($w / 2) - ($textfont->getWidth() / 2) + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $textfont->getHeight() - $textfont->getUnderBaseline() + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale;
$textfont->draw($im, $this->colorFg->allocate($im), $xPosition, $yPosition);
} elseif($this->textfont !== 0) {
$xPosition = ($w / 2) - (strlen($label) / 2) * imagefontwidth($this->textfont) + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale;
imagestring($im, $this->textfont, $xPosition, $yPosition, $label, $this->colorFg->allocate($im));
}
}
}
/**
* Method that saves FALSE into the checksumValue. This means no checksum
* but this method should be overloaded when needed.
*/
function calculateChecksum() { // protected
$this->checksumValue = false;
}
/**
* Returns FALSE because there is no checksum. This method should be
* overloaded to return correctly the checksum in string with checksumValue.
*
* @return string
*/
function processChecksum() { // protected
return false;
}
}

View File

@@ -0,0 +1,147 @@
<?php
/**
* BCGColor.php
*--------------------------------------------------------------------
*
* Holds Color in RGB Format.
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil New functionality
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGColor.php,v 1.7 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.6
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
class BCGColor {
var $r, $g, $b; // int Hexadecimal Value
/**
* Save RGB value into the classes
*
* There are 4 way to associate color with this classes :
* 1. Gives 3 parameters int (R, G, B)
* 2. Gives 1 parameter string hex value (#ff0000) (preceding with #)
* 3. Gives 1 parameter int hex value (0xff0000)
* 4. Gives 1 parameter string color code (white, black, orange...)
*
* @param mixed ...
*/
function BCGColor() {
$args = func_get_args();
$c = count($args);
if ($c === 3) {
$this->r = intval($args[0]);
$this->g = intval($args[1]);
$this->b = intval($args[2]);
} elseif ($c === 1) {
if (is_string($args[0]) && strlen($args[0]) === 7 && $args[0]{0} === '#') { // Hex Value in String
$this->r = intval(substr($args[0], 1, 2), 16);
$this->g = intval(substr($args[0], 3, 2), 16);
$this->b = intval(substr($args[0], 5, 2), 16);
} else {
if (is_string($args[0])) {
$args[0] = BCGColor::getColor($args[0]);
}
$args[0] = intval($args[0]);
$this->r = ($args[0] & 0xff0000) >> 16;
$this->g = ($args[0] & 0x00ff00) >> 8;
$this->b = ($args[0] & 0x0000ff);
}
} else {
$this->r = $this->g = $this->b = 0;
}
}
/**
* Returns Red Color
*
* @return int
*/
function r() {
return $this->r;
}
/**
* Returns Green Color
*
* @return int
*/
function g() {
return $this->g;
}
/**
* Returns Blue Color
*
* @return int
*/
function b() {
return $this->b;
}
/**
* Returns the int value for PHP color
*
* @param resource $im
* @return int
*/
function allocate(&$im) {
return imagecolorallocate($im, $this->r, $this->g, $this->b);
}
/**
* Returns class of BCGColor depending of the string color
*
* If the color doens't exist, it takes the default one.
*
* @param string $code
* @param string $default
*/
function getColor($code, $default = 'white') { // static
switch(strtolower($code)) {
case '':
case 'white':
return 0xffffff;
case 'black':
return 0x000000;
case 'maroon':
return 0x800000;
case 'red':
return 0xff0000;
case 'orange':
return 0xffa500;
case 'yellow':
return 0xffff00;
case 'olive':
return 0x808000;
case 'purple':
return 0x800080;
case 'fuchsia':
return 0xff00ff;
case 'lime':
return 0x00ff00;
case 'green':
return 0x008000;
case 'navy':
return 0x000080;
case 'blue':
return 0x0000ff;
case 'aqua':
return 0x00ffff;
case 'teal':
return 0x008080;
case 'silver':
return 0xc0c0c0;
case 'gray':
return 0x808080;
default:
return BCGColor::getColor($default, 'white');
}
}
};
?>

View File

@@ -0,0 +1,196 @@
<?php
/**
* BCGDrawing.php
*--------------------------------------------------------------------
*
* Holds the drawing $im
* You can use get_im() to add other kind of form not held into these classes.
*
*--------------------------------------------------------------------
* Revision History
* v2.1.0 8 nov 2009 Jean-Sébastien Goupil Support DPI, Rotation
* v2.0.1 8 mar 2009 Jean-Sébastien Goupil Supports GIF and WBMP
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil Just one barcode per drawing
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGDrawing.php,v 1.10 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.12
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode.php');
include_once('drawer/BCGDrawJPG.php');
include_once('drawer/BCGDrawPNG.php');
class BCGDrawing {
var $IMG_FORMAT_PNG = 1; // const
var $IMG_FORMAT_JPEG = 2; // const
var $IMG_FORMAT_GIF = 3; // const
var $IMG_FORMAT_WBMP = 4; // const
var $w, $h; // int
var $color; // BCGColor
var $filename; // char *
var $im; // {object}
var $barcode; // BCGBarcode
var $dpi; // int
var $rotateDegree; // float
/**
* Constructor
*
* @param int $w
* @param int $h
* @param string filename
* @param BCGColor $color
*/
function BCGDrawing($filename, &$color) {
$this->im = null;
$this->setFilename($filename);
$this->color =& $color;
$this->dpi = null;
$this->rotateDegree = 0.0;
}
/**
* Destructor
*/
//public function __destruct() {
// $this->destroy();
//}
/**
* Sets the filename
*
* @param string $filaneme
*/
function setFilename($filename) {
$this->filename = $filename;
}
/**
* Init Image and color background
*/
function init() {
if($this->im === null) {
$this->im = imagecreatetruecolor($this->w, $this->h)
or die('Can\'t Initialize the GD Libraty');
imagefilledrectangle($this->im, 0, 0, $this->w - 1, $this->h - 1, $this->color->allocate($this->im));
}
}
/**
* @return resource
*/
function &get_im() {
return $this->im;
}
/**
* @param resource $im
*/
function set_im(&$im) {
$this->im = $im;
}
/**
* Set Barcode for drawing
*
* @param BCGBarcode $barcode
*/
function setBarcode(&$barcode) {
$this->barcode =& $barcode;
}
/**
* Get the DPI for supported filetype
*
* @return int
*/
function getDPI() {
return $this->dpi;
}
/**
* Set the DPI for supported filetype
*
* @param float $dpi
*/
function setDPI($dpi) {
$this->dpi = $dpi;
}
/**
* Get the rotation angle in degree
*
* @return float
*/
function getRotationAngle() {
return $this->rotateDegree;
}
/**
* Set the rotation angle in degree
*
* @param float $degree
*/
function setRotationAngle($degree) {
$this->rotateDegree = (float)$degree;
}
/**
* Draw the barcode on the image $im
*/
function draw() {
$size = $this->barcode->getMaxSize();
$this->w = max(1, $size[0]);
$this->h = max(1, $size[1]);
$this->init();
$this->barcode->draw($this->im);
}
/**
* Save $im into the file (many format available)
*
* @param int $image_style
* @param int $quality
*/
function finish($image_style = 2, $quality = 100) {
$drawer = null;
$im = $this->im;
if($this->rotateDegree > 0.0) {
$im = imagerotate($this->im, $this->rotateDegree, $this->color->allocate($this->im));
}
if ($image_style === $this->IMG_FORMAT_PNG) {
$drawer = new BCGDrawPNG($im);
$drawer->setFilename($this->filename);
$drawer->setDPI($this->dpi);
} elseif ($image_style === $this->IMG_FORMAT_JPEG) {
$drawer = new BCGDrawJPG($im);
$drawer->setFilename($this->filename);
$drawer->setDPI($this->dpi);
$drawer->setQuality($quality);
} elseif ($image_style === $this->IMG_FORMAT_GIF) {
imagegif($this->im, $this->filename);
} elseif ($image_style === $this->IMG_FORMAT_WBMP) {
imagewbmp($this->im, $this->filename);
}
if($drawer !== null) {
$drawer->draw();
}
}
/**
* Free the memory of PHP (called also by destructor)
*/
function destroy() {
@imagedestroy($this->im);
}
};
?>

View File

@@ -0,0 +1,102 @@
<?php
/**
* BCGFont.php
*--------------------------------------------------------------------
*
* Holds font family and size.
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3 6 feb 2006 Jean-Sébastien Goupil Correct getWidth()
* v1.2.3b 30 dec 2005 Jean-Sébastien Goupil Add getUnderBaseline()
* V1.2.1 27 jun 2005 Jean-Sebastien Goupil New
*--------------------------------------------------------------------
* $Id: BCGFont.php,v 1.6 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.7
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
class BCGFont {
var $path;
var $text;
var $size;
var $box;
/**
* Constructor
*
* @param string $fontPath path to the file
* @param int $size size in point
*/
function BCGFont($fontPath, $size) {
$this->path = $fontPath;
$this->size = $size;
}
/**
* Text associated to the font
*
* @param string text
*/
function setText($text) {
$this->text = $text;
$im = imagecreate(1, 1);
$this->box = imagettftext($im, $this->size, 0, 0, 0, imagecolorallocate($im, 0, 0, 0), $this->path, $this->text);
}
/**
* Returns the width that the text takes to be written
*
* @return float
*/
function getWidth() {
if ($this->box !== NULL) {
// Bug fixed : a number is aligned on the "right" in the box...
// If we are writting the number "1" with minX at 2 and maxX at 10
// The maxWidth will be 10 and not 8 because we don't squeeze the number
// on its left. So now we don't remove the minX.
return abs(max($this->box[2], $this->box[4]));
} else {
return 0;
}
}
/**
* Returns the height that the text takes.
*
* @return float
*/
function getHeight() {
if ($this->box !== NULL) {
return (float) abs(max($this->box[5], $this->box[7]) - min($this->box[1], $this->box[3]));
} else {
return 0.0;
}
}
/**
* Returns the number of pixel under the baseline located at 0.
*
* @return float
*/
function getUnderBaseline() {
// Y for imagettftext : This sets the position of the fonts baseline, not the very bottom of the character.
return (float) max($this->box[1], $this->box[3]);
}
/**
* Draws the text on the image at a specific position.
* $x and $y represent the left bottom corner.
*
* @param resource $im
* @param int $color
* @param int $x
* @param int $y
*/
function draw(&$im, $color, $x, $y) {
imagettftext($im, $this->size, 0, $x, $y, $color, $this->path, $this->text);
}
}
?>

View File

@@ -0,0 +1,121 @@
<?php
/**
* BCGcodabar.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - Codabar
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update + fix B and C
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil PHP5.1 compatible
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGcodabar.barcode.php,v 1.9 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.11
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGcodabar extends BCGBarcode1D {
/**
* Constructor
*/
function BCGcodabar() { // public
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9','-','$',':','/','.','+','A','B','C','D');
$this->code = array( // 0 added to add an extra space
'00000110', /* 0 */
'00001100', /* 1 */
'00010010', /* 2 */
'11000000', /* 3 */
'00100100', /* 4 */
'10000100', /* 5 */
'01000010', /* 6 */
'01001000', /* 7 */
'01100000', /* 8 */
'10010000', /* 9 */
'00011000', /* - */
'00110000', /* $ */
'10001010', /* : */
'10100010', /* / */
'10101000', /* . */
'00111110', /* + */
'00110100', /* A */
'01010010', /* B */
'00010110', /* C */
'00011100' /* D */
);
}
/**
* Saves Text
*
* @param string $text
*/
function parse($text) {
BCGBarcode1D::parse(strtoupper($text)); // Only Capital Letters are Allowed
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Must start by A, B, C or D
if($this->text[0] !== 'A' && $this->text[0] !== 'B' && $this->text[0] !== 'C' && $this->text[0] !== 'D') {
$this->drawError($im, 'Must start by char A, B, C or D.');
$error_stop = true;
}
// Must over by A, B, C or D
$c2 = $c - 1;
if($c2 === 0 || ($this->text[$c2] !== 'A' && $this->text[$c2] !== 'B' && $this->text[$c2] !== 'C' && $this->text[$c2] !== 'D')) {
$this->drawError($im, 'Must end by char A, B, C or D.');
$error_stop = true;
}
if($error_stop === false) {
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->text[$i]), true);
}
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$w = 0;
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
$index = $this->findIndex($this->text[$i]);
if($index !== false) {
$w += 8;
$w += substr_count($this->code[$index], '1');
}
}
return array($p[0] + $w * $this->scale, $p[1]);
}
};
?>

View File

@@ -0,0 +1,164 @@
<?php
/**
* BCGcode11.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - Code 11
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3b 30 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible + Error in checksum
* v1.2.2 23 jul 2005 Jean-Sébastien Goupil WS Fix
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGcode11.barcode.php,v 1.9 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.11
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGcode11 extends BCGBarcode1D {
/**
* Constructor
*/
function BCGcode11() { // public
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9','-');
$this->code = array( // 0 added to add an extra space
'000010', /* 0 */
'100010', /* 1 */
'010010', /* 2 */
'110000', /* 3 */
'001010', /* 4 */
'101000', /* 5 */
'011000', /* 6 */
'000110', /* 7 */
'100100', /* 8 */
'100000', /* 9 */
'001000' /* - */
);
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im,'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Starting Code
$this->drawChar($im, '001100', true);
// Chars
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->text[$i]), true);
}
// Checksum
$this->calculateChecksum();
$c = count($this->checksumValue);
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->code[$this->checksumValue[$i]], true);
}
// Ending Code
$this->drawChar($im, '00110', true);
$this->drawText($im);
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$w = 0;
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
$index = $this->findIndex($this->text[$i]);
if($index !== false) {
$w += 6;
$w += substr_count($this->code[$index], '1');
}
}
$startlength = 8 * $this->scale;
$textlength = $w * $this->scale;
// We take the max length possible for checksums (it is 7 or 8...)
$checksumlength = 8 * $this->scale;
if($c >= 10) {
$checksumlength += 8 * $this->scale;
}
$endlength = 7 * $this->scale;
return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Checksum
// First CheckSUM "C"
// The "C" checksum character is the modulo 11 remainder of the sum of the weighted
// value of the data characters. The weighting value starts at "1" for the right-most
// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.
// After 10, the sequence wraps around back to 1.
// Second CheckSUM "K"
// Same as CheckSUM "C" but we count the CheckSum "C" at the end
// After 9, the sequence wraps around back to 1.
$sequence_multiplier = array(10, 9);
$temp_text = $this->text;
$this->checksumValue = array();
for($z = 0; $z < 2; $z++) {
$c = strlen($temp_text);
// We don't display the K CheckSum if the original text had a length less than 10
if($c <= 10 && $z === 1) {
break;
}
$checksum = 0;
for($i = $c, $j = 0; $i > 0; $i--, $j++) {
$multiplier = $i % $sequence_multiplier[$z];
if($multiplier === 0) {
$multiplier = $sequence_multiplier[$z];
}
$checksum += $this->findIndex($temp_text[$j]) * $multiplier;
}
$this->checksumValue[$z] = $checksum % 11;
$temp_text .= $this->keys[$this->checksumValue[$z]];
}
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
$ret = '';
$c = count($this->checksumValue);
for($i = 0; $i < $c; $i++) {
$ret .= $this->keys[$this->checksumValue[$i]];
}
return $ret;
}
return false;
}
};
?>

View File

@@ -0,0 +1,874 @@
<?php
/**
* BCGcode128.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - Code 128, A, B, C
*
* # Code C Working properly only on PHP4 or PHP5.0.3+ due to bug :
* http://bugs.php.net/bug.php?id=28862
*
* !! Warning !!
* If you display the checksum on the label, you may obtain
* some garbage since some characters are not displayable.
*
*--------------------------------------------------------------------
* Revision History
* v2.1.0 8 nov 2009 Jean-Sébastien Goupil Specify exact table for encoding
* v2.0.1 8 mar 2009 Jean-Sébastien Goupil Fix Code 128 C
* v2.00 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3pl2 27 sep 2006 Jean-Sébastien Goupil There were some errors dealing with C table
* v1.2.3b 30 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added + Correct bug if passing C to another code
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGcode128.barcode.php,v 1.13 2010/02/14 00:25:14 jsgoupil Exp $
* PHP5-Revision: 1.17
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
define('CODE128_A', 1); // Table A
define('CODE128_B', 2); // Table B
define('CODE128_C', 3); // Table C
class BCGcode128 extends BCGBarcode1D {
var $KEYA_FNC3 = 96; // const
var $KEYA_FNC2 = 97; // const
var $KEYA_SHIFT = 98; // const
var $KEYA_CODEC = 99; // const
var $KEYA_CODEB = 100; // const
var $KEYA_FNC4 = 101; // const
var $KEYA_FNC1 = 102; // const
var $KEYB_FNC3 = 96; // const
var $KEYB_FNC2 = 97; // const
var $KEYB_SHIFT = 98; // const
var $KEYB_CODEC = 99; // const
var $KEYB_FNC4 = 100; // const
var $KEYB_CODEA = 101; // const
var $KEYB_FNC1 = 102; // const
var $KEYC_CODEB = 100; // const
var $KEYC_CODEA = 101; // const
var $KEYC_FNC1 = 102; // const
var $KEY_STARTA = 103; // const
var $KEY_STARTB = 104; // const
var $KEY_STARTC = 105; // const
var $KEY_STOP = 106; // const
var $keysA, $keysB, $keysC;
var $starting_text;
var $indcheck, $data;
var $tilde;
var $errorText;
var $shift;
var $latch;
var $fnc;
var $METHOD = NULL; // Array of method available to create PDF417 (PDF417_TM, PDF417_NM, PDF417_BM)
/**
* Constructor
*
* @param char $start
*/
function BCGcode128($start = NULL) { // public
BCGBarcode1D::BCGBarcode1D();
/* CODE 128 A */
$this->keysA = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';
for($i = 0; $i < 32; $i++) {
$this->keysA .= chr($i);
}
/* CODE 128 B */
$this->keysB = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127);
/* CODE 128 C */
$this->keysC = '0123456789';
$this->code = array(
'101111', /* 00 */
'111011', /* 01 */
'111110', /* 02 */
'010112', /* 03 */
'010211', /* 04 */
'020111', /* 05 */
'011102', /* 06 */
'011201', /* 07 */
'021101', /* 08 */
'110102', /* 09 */
'110201', /* 10 */
'120101', /* 11 */
'001121', /* 12 */
'011021', /* 13 */
'011120', /* 14 */
'002111', /* 15 */
'012011', /* 16 */
'012110', /* 17 */
'112100', /* 18 */
'110021', /* 19 */
'110120', /* 20 */
'102101', /* 21 */
'112001', /* 22 */
'201020', /* 23 */
'200111', /* 24 */
'210011', /* 25 */
'210110', /* 26 */
'201101', /* 27 */
'211001', /* 28 */
'211100', /* 29 */
'101012', /* 30 */
'101210', /* 31 */
'121010', /* 32 */
'000212', /* 33 */
'020012', /* 34 */
'020210', /* 35 */
'001202', /* 36 */
'021002', /* 37 */
'021200', /* 38 */
'100202', /* 39 */
'120002', /* 40 */
'120200', /* 41 */
'001022', /* 42 */
'001220', /* 43 */
'021020', /* 44 */
'002012', /* 45 */
'002210', /* 46 */
'022010', /* 47 */
'202010', /* 48 */
'100220', /* 49 */
'120020', /* 50 */
'102002', /* 51 */
'102200', /* 52 */
'102020', /* 53 */
'200012', /* 54 */
'200210', /* 55 */
'220010', /* 56 */
'201002', /* 57 */
'201200', /* 58 */
'221000', /* 59 */
'203000', /* 60 */
'110300', /* 61 */
'320000', /* 62 */
'000113', /* 63 */
'000311', /* 64 */
'010013', /* 65 */
'010310', /* 66 */
'030011', /* 67 */
'030110', /* 68 */
'001103', /* 69 */
'001301', /* 70 */
'011003', /* 71 */
'011300', /* 72 */
'031001', /* 73 */
'031100', /* 74 */
'130100', /* 75 */
'110003', /* 76 */
'302000', /* 77 */
'130001', /* 78 */
'023000', /* 79 */
'000131', /* 80 */
'010031', /* 81 */
'010130', /* 82 */
'003101', /* 83 */
'013001', /* 84 */
'013100', /* 85 */
'300101', /* 86 */
'310001', /* 87 */
'310100', /* 88 */
'101030', /* 89 */
'103010', /* 90 */
'301010', /* 91 */
'000032', /* 92 */
'000230', /* 93 */
'020030', /* 94 */
'003002', /* 95 */
'003200', /* 96 */
'300002', /* 97 */
'300200', /* 98 */
'002030', /* 99 */
'003020', /* 100*/
'200030', /* 101*/
'300020', /* 102*/
'100301', /* 103*/
'100103', /* 104*/
'100121', /* 105*/
'122000' /*STOP*/
);
$this->errorText = '';
$this->setStart($start);
$this->setTilde(true);
// Latches and Shifts
$this->latch = array(
array(null, $this->KEYA_CODEB, $this->KEYA_CODEC),
array($this->KEYB_CODEA, null, $this->KEYB_CODEC),
array($this->KEYC_CODEA, $this->KEYC_CODEB, null)
);
$this->shift = array(
array(null, $this->KEYA_SHIFT),
array($this->KEYB_SHIFT, null)
);
$this->fnc = array(
array($this->KEYA_FNC1, $this->KEYA_FNC2, $this->KEYA_FNC3, $this->KEYA_FNC4),
array($this->KEYB_FNC1, $this->KEYB_FNC2, $this->KEYB_FNC3, $this->KEYB_FNC4),
array($this->KEYC_FNC1, null, null, null)
);
// Method available
$this->METHOD = array(CODE128_A => 'A', CODE128_B => 'B', CODE128_C => 'C');
}
/**
* Specifies the start code. Can be 'A', 'B', 'C' or NULL
* - Table A: Capitals + ASCII 0-31 + punct
* - Table B: Capitals + LowerCase + punct
* - Table C: Numbers
*
* If NULL is specified, the table selection is automatically made.
* The default is NULL.
*
* @param string $table
*/
function setStart($table) {
if($table !== 'A' && $table !== 'B' && $table !== 'C' && $table !== NULL) $table = NULL;
$this->starting_text = $table;
}
/**
* Accepts tilde to be process as a special character.
* If true, you can do this:
* - ~~ : to make ONE tilde
* - ~Fx : to insert FCNx. x is equal from 1 to 4.
*
* @param boolean $accept
*/
function setTilde($accept) {
$this->tilde = (bool)$accept;
}
/**
* Saves Text
*
* @param string $text
*/
function parse($text) {
$this->setStartFromText($text);
$this->errorText = ''; // Reset Error
$this->text = '';
$seq = '';
$currentMode = $this->starting_text;
// Here, we format correctly what the user gives.
if(!is_array($text)) {
$seq = $this->getSequence($text, $currentMode);
$this->text = $text;
} else {
// This loop checks for UnknownText AND raises an error if a character is not allowed in a table
reset($text);
while(list($key1, $val1) = each($text)) { // We take each value
if(!is_array($val1)) { // This is not a table
if(is_string($val1)) { // If it's a string, parse as unknown
$seq .= $this->getSequence($val1, $currentMode);
$this->text .= $val1;
} else {
// it's the case of "array(ENCODING, 'text')"
// We got ENCODING in $val1, calling 'each' again will get 'text' in $val2
list($key2, $val2) = each($text);
$seq .= $this->{'setParse' . $this->METHOD[$val1]}($val2, $currentMode);
$this->text .= $val2;
}
} else { // The method is specified
// $val1[0] = ENCODING
// $val1[1] = 'text'
$value = isset($val1[1]) ? $val1[1] : ''; // If data available
$seq .= $this->{'setParse' . $this->METHOD[$val1[0]]}($value, $currentMode);
$this->text .= $value;
}
if($this->errorText) {
break;
}
}
}
if($seq !== '') {
$bitstream = $this->createBinaryStream($this->text, $seq);
$this->setData($bitstream);
}
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
if(!empty($this->errorText)) {
$this->drawError($im, $this->errorText);
} else {
$c = count($this->data);
if($c === 0) {
$this->drawError($im, 'No text has been entered.');
} else {
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->data[$i], true);
}
$this->drawChar($im, '1', true);
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
// Contains start + text + checksum + stop
$textlength = count($this->data) * 11 * $this->scale;
$endlength = 2 * $this->scale; // + final bar
return array($p[0] + $textlength + $endlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Checksum
// First Char (START)
// + Starting with the first data character following the start character,
// take the value of the character (between 0 and 102, inclusive) multiply
// it by its character position (1) and add that to the running checksum.
// Modulated 103
$this->checksumValue = $this->indcheck[0];
$c = count($this->indcheck);
for($i = 1; $i < $c; $i++) {
$this->checksumValue += $this->indcheck[$i] * $i;
}
$this->checksumValue = $this->checksumValue % 103;
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
}
/**
* Specifies the starting_text table if none has been specified earlier.
*
* @param string $text
*/
function setStartFromText($text) {
if($this->starting_text === NULL) {
// If we have a forced table at the start, we get that one...
if(is_array($text)) {
if(is_array($text[0])) {
// Code like array(array(ENCODING, ''))
$this->starting_text = $this->METHOD[$text[0][0]];
return;
} else {
if(is_string($text[0])) {
// Code like array('test') (Automatic text)
$text = $text[0];
} else {
// Code like array(ENCODING, '')
$this->starting_text = $this->METHOD[$text[0]];
return;
}
}
}
// At this point, we had an "automatic" table selection...
// If we can get at least 4 numbers, go in C; otherwise go in B.
$tmp = preg_quote($this->keysC, '/');
if(strlen($text) >= 4 && preg_match('/[' . $tmp . ']/', substr($text, 0, 4))) {
$this->starting_text = 'C';
} else {
if(strpos($this->keysB, $text[0])) {
$this->starting_text = 'B';
} else {
$this->starting_text = 'A';
}
}
}
}
/**
* Extracts the ~ value from the $text at the $pos.
* If the tilde is not ~~, ~F1, ~F2, ~F3, ~F4; an error is raised.
*
* @param string $text
* @param int $pos
* @return string
*/
function extractTilde($text, $pos) {
if($text[$pos] === '~') {
if(isset($text[$pos + 1])) {
// Do we have a tilde?
if($text[$pos + 1] === '~') {
return '~~';
} elseif($text[$pos + 1] === 'F') {
// Do we have a number after?
if(isset($text[$pos + 2])) {
$v = intval($text[$pos + 2]);
if($v >= 1 && $v <= 4) {
return '~F' . $v;
} else {
$this->errorText = 'Bad ~F. You must provide a number from 1 to 4.';
return '';
}
} else {
$this->errorText = 'Bad ~F. You must provide a number from 1 to 4.';
return '';
}
} else {
// Wrong code
$this->errorText = 'Wrong code after the ~.';
return '';
}
} else {
// Wrong code
$this->errorText = 'Wrong code after the ~.';
return '';
}
} else {
// Can't happen
$this->errorText = 'There is no ~ at this location';
return '';
}
}
/**
* Gets the "dotted" sequence for the $text based on the $currentMode.
* There is also a check if we use the special tilde ~
*
* @param string $text
* @param string $currentMode
* @return string
*/
function getSequenceParsed($text, $currentMode) {
if($this->tilde) {
$sequence = '';
$previousPos = 0;
while(($pos = strpos($text, '~', $previousPos)) !== false) {
$tildeData = $this->extractTilde($text, $pos);
if($tildeData === '') {
// Something bad happened in extractTilde(). The errorText is already populated.
return '';
}
$simpleTilde = ($tildeData === '~~');
if($simpleTilde && $currentMode !== 'B') {
$this->errorText = 'The Table ' . $currentMode . ' doesn\'t contain the character ~.';
return '';
}
// At this point, we know we have ~Fx
if($tildeData !== '~F1' && $currentMode === 'C') {
// The mode C doesn't support ~F2, ~F3, ~F4
$this->errorText = 'The Table C doesn\'t contain the function ' . $tildeData . '.';
return '';
}
$length = $pos - $previousPos;
if($currentMode === 'C') {
if($length % 2 === 1) {
$this->errorText = 'The text "'.$text.'" must have an even number of character to be encoded in Table C.';
return '';
}
}
$sequence .= str_repeat('.', $length);
$sequence .= '.';
$sequence .= (!$simpleTilde) ? 'F' : '';
$previousPos = $pos + strlen($tildeData);
}
// Flushing
$length = strlen($text) - $previousPos;
if($currentMode === 'C') {
if($length % 2 === 1) {
$this->errorText = 'The text "'.$text.'" must have an even number of character to be encoded in Table C.';
return '';
}
}
$sequence .= str_repeat('.', $length);
return $sequence;
} else {
return str_repeat('.', strlen($text));
}
}
/**
* Parses the text and returns the appropriate sequence for the Table A.
*
* @param string $text
* @param string $currentMode
* @return string
*/
function setParseA($text, &$currentMode) {
$tmp = preg_quote($this->keysA, '/');
// If we accept the ~ for special character, we must allow it.
if($this->tilde) {
$tmp .= '~';
}
$match = array();
if(preg_match('/[^' . $tmp . ']/', $text, $match) === 1) {
// We found something not allowed
$this->errorText = 'The text "' . $text . '" can\'t be parsed with the Table A. The character "' . $match[0] . '" is not allowed.';
return '';
} else {
$latch = ($currentMode === 'A') ? '' : '0';
$currentMode = 'A';
return $latch . $this->getSequenceParsed($text, $currentMode);
}
}
/**
* Parses the text and returns the appropriate sequence for the Table B.
*
* @param string $text
* @param string $currentMode
* @return string
*/
function setParseB($text, &$currentMode) {
$tmp = preg_quote($this->keysB, '/');
$match = array();
if(preg_match('/[^' . $tmp . ']/', $text, $match) === 1) {
// We found something not allowed
$this->errorText = 'The text "'.$text.'" can\'t be parsed with the Table B. The character "' . $match[0] . '" is not allowed.';
return '';
} else {
$latch = ($currentMode === 'B') ? '' : '1';
$currentMode = 'B';
return $latch . $this->getSequenceParsed($text, $currentMode);
}
}
/**
* Parses the text and returns the appropriate sequence for the Table C.
*
* @param string $text
* @param string $currentMode
* @return string
*/
function setParseC($text, &$currentMode) {
$tmp = preg_quote($this->keysC, '/');
// If we accept the ~ for special character, we must allow it.
if($this->tilde) {
$tmp .= '~F';
}
$match = array();
if(preg_match('/[^' . $tmp . ']/', $text, $match) === 1) {
// We found something not allowed
$this->errorText = 'The text "'.$text.'" can\'t be parsed with the Table C. The character "' . $match[0] . '" is not allowed.';
return '';
} else {
$latch = ($currentMode === 'C') ? '' : '2';
$currentMode = 'C';
return $latch . $this->getSequenceParsed($text, $currentMode);
}
}
/**
* Depending on the $text, it will return the correct
* sequence to encode the text.
*
* @param string $text
* @param string $starting_text
* @return string
*/
function getSequence(&$text, &$starting_text) {
$e = 10000;
$latLen = array(
array(0, 1, 1),
array(1, 0, 1),
array(1, 1, 0)
);
$shftLen = array(
array($e, 1, $e),
array(1, $e, $e),
array($e, $e, $e)
);
$charSiz = array(2, 2, 1);
$startA = $e;
$startB = $e;
$startC = $e;
if($starting_text === 'A') $startA = 0;
if($starting_text === 'B') $startB = 0;
if($starting_text === 'C') $startC = 0;
$curLen = array($startA, $startB, $startC);
$curSeq = array(null, null, null);
$nextNumber = false;
$x = 0;
$xLen = strlen($text);
for($x = 0; $x < $xLen; $x++) {
$input = $text[$x];
// 1.
for($i = 0; $i < 3; $i++) {
for($j = 0; $j < 3; $j++) {
if(($curLen[$i] + $latLen[$i][$j]) < $curLen[$j]) {
$curLen[$j] = $curLen[$i] + $latLen[$i][$j];
$curSeq[$j] = $curSeq[$i] . $j;
}
}
}
// 2.
$nxtLen = array($e, $e, $e);
$nxtSeq = array();
// 3.
$flag = false;
$posArray = array();
// Special case, we do have a tilde and we process them
if($this->tilde && $input === '~') {
$tildeData = $this->extractTilde($text, $x);
if($tildeData === '') {
// Something bad happened in extractTilde(). The errorText is already populated.
return '';
} elseif($tildeData === '~~') {
// We simply skip a tilde
$posArray[] = 1;
$x++;
} elseif(substr($tildeData, 0, 2) === '~F') {
$v = intval($tildeData[2]);
$posArray[] = 0;
$posArray[] = 1;
if($v === 1) {
$posArray[] = 2;
}
$x += 2;
$flag = true;
}
} else {
$pos = strpos($this->keysA, $input);
if($pos !== false) {
$posArray[] = 0;
}
$pos = strpos($this->keysB, $input);
if($pos !== false) {
$posArray[] = 1;
}
$pos = strpos($this->keysC, $input);
// Do we have the next char a number?? OR a ~F1
if($nextNumber || ($pos !== false && isset($text[$x + 1]) && strpos($this->keysC, $text[$x + 1]) !== false)) {
$nextNumber = !$nextNumber;
$posArray[] = 2;
}
}
$c = count($posArray);
for($i = 0; $i < $c; $i++) {
if(($curLen[$posArray[$i]] + $charSiz[$posArray[$i]]) < $nxtLen[$posArray[$i]]) {
$nxtLen[$posArray[$i]] = $curLen[$posArray[$i]] + $charSiz[$posArray[$i]];
$nxtSeq[$posArray[$i]] = $curSeq[$posArray[$i]] . '.';
}
for($j = 0; $j < 2; $j++) {
if($j === $posArray[$i]) continue;
if(($curLen[$j] + $shftLen[$j][$posArray[$i]] + $charSiz[$posArray[$i]]) < $nxtLen[$j]) {
$nxtLen[$j] = $curLen[$j] + $shftLen[$j][$posArray[$i]] + $charSiz[$posArray[$i]];
$nxtSeq[$j] = $curSeq[$j] . chr($posArray[$i] + 65) . '.';
}
}
}
if($c === 0) {
// We found an unsuported character
$this->errorText = 'Character ' . $input . ' not supported.';
return '';
}
if($flag) {
for($i = 0; $i < 5; $i++) {
if(isset($nxtSeq[$i])) {
$nxtSeq[$i] .= 'F';
}
}
}
// 4.
for($i = 0; $i < 3; $i++) {
$curLen[$i] = $nxtLen[$i];
if(isset($nxtSeq[$i])) {
$curSeq[$i] = $nxtSeq[$i];
}
}
}
// Every curLen under $e are possible but we take the smallest !
$m = $e;
$k = -1;
for($i = 0; $i < 3; $i++) {
if($curLen[$i] < $m) {
$k = $i;
$m = $curLen[$i];
}
}
if($k === -1) {
return '';
}
$starting_text = chr($k + 65);
return $curSeq[$k];
}
/**
* Depending on the sequence $seq given (returned from getSequence()),
* this method will return the code stream in an array. Each char will be a
* string of bit based on the Code 128.
*
* Each letter from the sequence represents bits.
*
* 0 to 2 are latches
* A to B are Shift + Letter
* . is a char in the current encoding
*
* @param string $text
* @param string $seq
* @return string[][]
*/
function createBinaryStream($text, $seq) {
$c = strlen($seq);
$data = array(); // code stream
$indcheck = array(); // index for checksum
$currentEncoding = 0;
if($this->starting_text === 'A') {
$currentEncoding = 0;
$indcheck[] = $this->KEY_STARTA;
} elseif($this->starting_text === 'B') {
$currentEncoding = 1;
$indcheck[] = $this->KEY_STARTB;
} elseif($this->starting_text === 'C') {
$currentEncoding = 2;
$indcheck[] = $this->KEY_STARTC;
}
$data[] = $this->code[103 + $currentEncoding];
$temporaryEncoding = -1;
for($i = 0, $counter = 0; $i < $c; $i++) {
$input = $seq[$i];
$inputI = intval($input);
if($input === '.') {
$this->encodeChar($data, $currentEncoding, $seq, $text, $i, $counter, $indcheck);
if($temporaryEncoding !== -1) {
$currentEncoding = $temporaryEncoding;
$temporaryEncoding = -1;
}
} elseif($input >= 'A' && $input <= 'B') {
// We shift
$encoding = ord($input) - 65;
$shift = $this->shift[$currentEncoding][$encoding];
$indcheck[] = $shift;
$data[] = $this->code[$shift];
if($temporaryEncoding === -1) {
$temporaryEncoding = $currentEncoding;
}
$currentEncoding = $encoding;
} elseif($inputI >= 0 && $inputI < 3) {
$temporaryEncoding = -1;
// We latch
$latch = $this->latch[$currentEncoding][$inputI];
if($latch !== NULL) {
$indcheck[] = $latch;
$data[] = $this->code[$latch];
$currentEncoding = $inputI;
}
}
}
return array($indcheck, $data);
}
function encodeChar(&$data, $encoding, $seq, $text, &$i, &$counter, &$indcheck) {
if(isset($seq[$i + 1]) && $seq[$i + 1] === 'F') {
// We have a flag !!
if($text[$counter + 1] === 'F') {
$number = $text[$counter + 2];
$fnc = $this->fnc[$encoding][$number - 1];
$indcheck[] = $fnc;
$data[] = $this->code[$fnc];
// Skip F + number
$counter += 2;
} else {
// Not supposed
}
$i++;
} else {
if($encoding === 2) {
// We take 2 numbers in the same time
$code = (int)substr($text, $counter, 2);
$indcheck[] = $code;
$data[] = $this->code[$code];
$counter++;
$i++;
} else {
$keys = ($encoding === 0) ? $this->keysA : $this->keysB;
$pos = strpos($keys, $text[$counter]);
$indcheck[] = $pos;
$data[] = $this->code[$pos];
}
}
$counter++;
}
/**
* Saves data into the classes.
*
* This method will save data, calculate real column number
* (if -1 was selected), the real error level (if -1 was
* selected)... It will add Padding to the end and generate
* the error codes.
*
* @param array $data
*/
function setData($data) {
$this->indcheck = $data[0];
$this->data = $data[1];
$this->calculateChecksum();
$this->data[] = $this->code[$this->checksumValue];
$this->data[] = $this->code[$this->KEY_STOP];
}
};
?>

View File

@@ -0,0 +1,183 @@
<?php
/**
* BCGcode39.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - Code 39
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3b 30 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* v1.01 7 jul 2004 Jean-Sebastien Goupil Correction + Sign
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGcode39.barcode.php,v 1.8 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.10
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGcode39 extends BCGBarcode1D {
var $starting, $ending;
var $checksum;
/**
* Constructor
*/
function BCGcode39() { // public
BCGBarcode1D::BCGBarcode1D();
$this->starting = $this->ending = 43;
$this->keys = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','.',' ','$','/','+','%','*');
$this->code = array( // 0 added to add an extra space
'0001101000', /* 0 */
'1001000010', /* 1 */
'0011000010', /* 2 */
'1011000000', /* 3 */
'0001100010', /* 4 */
'1001100000', /* 5 */
'0011100000', /* 6 */
'0001001010', /* 7 */
'1001001000', /* 8 */
'0011001000', /* 9 */
'1000010010', /* A */
'0010010010', /* B */
'1010010000', /* C */
'0000110010', /* D */
'1000110000', /* E */
'0010110000', /* F */
'0000011010', /* G */
'1000011000', /* H */
'0010011000', /* I */
'0000111000', /* J */
'1000000110', /* K */
'0010000110', /* L */
'1010000100', /* M */
'0000100110', /* N */
'1000100100', /* O */
'0010100100', /* P */
'0000001110', /* Q */
'1000001100', /* R */
'0010001100', /* S */
'0000101100', /* T */
'1100000010', /* U */
'0110000010', /* V */
'1110000000', /* W */
'0100100010', /* X */
'1100100000', /* Y */
'0110100000', /* Z */
'0100001010', /* - */
'1100001000', /* . */
'0110001000', /* */
'0101010000', /* $ */
'0101000100', /* / */
'0100010100', /* + */
'0001010100', /* % */
'0100101000' /* * */
);
$this->setChecksum(false);
}
function setChecksum($checksum) {
$this->checksum = (bool)$checksum;
}
/**
* Saves Text
*
* @param string $text
*/
function parse($text) {
BCGBarcode1D::parse(strtoupper($text)); // Only Capital Letters are Allowed
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
if (array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if ($error_stop === false) {
// The * is not allowed
if (strpos($this->text, '*') !== false) {
$this->drawError($im, 'Char \'*\' not allowed.');
$error_stop = true;
}
if ($error_stop === false) {
// Starting *
$this->drawChar($im, $this->code[$this->starting], true);
// Chars
for ($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->text[$i]), true);
}
// Checksum (rarely used)
if ($this->checksum === true) {
$this->calculateChecksum();
$this->drawChar($im, $this->code[$this->checksumValue % 43], true);
}
// Ending *
$this->drawChar($im, $this->code[$this->ending], true);
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$textlength = 13 * strlen($this->text) * $this->scale;
$startlength = 13 * $this->scale;
$checksumlength = 0;
if ($this->checksum === true) {
$checksumlength = 13 * $this->scale;
}
$endlength = 13 * $this->scale;
return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
$this->checksumValue = 0;
$c = strlen($this->text);
for ($i = 0; $i < $c; $i++) {
$this->checksumValue += $this->findIndex($this->text[$i]);
}
$this->checksumValue = $this->checksumValue % 43;
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if ($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if ($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
}
};
?>

View File

@@ -0,0 +1,203 @@
<?php
/**
* BCGcode39extended.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - Code 39 Extended
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
*--------------------------------------------------------------------
* $Id: BCGcode39extended.barcode.php,v 1.3 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.3
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGcode39.barcode.php');
class BCGcode39extended extends BCGcode39 {
var $EXTENDED_1 = 39; // const
var $EXTENDED_2 = 40; // const
var $EXTENDED_3 = 41; // const
var $EXTENDED_4 = 42; // const
var $errorText;
var $indcheck, $data;
/**
* Constructor
*/
function BCGcode39extended() { // public
BCGcode39::BCGcode39();
// We just put parenthesis around special characters.
$this->keys[$this->EXTENDED_1] = '($)';
$this->keys[$this->EXTENDED_2] = '(/)';
$this->keys[$this->EXTENDED_3] = '(+)';
$this->keys[$this->EXTENDED_4] = '(%)';
$this->errorText = '';
}
/**
* Saves Text
*
* @param string $text
*/
function parse($text) {
$this->text = $text;
$data = array();
$indcheck = array();
$this->errorText = ''; // Reset Error
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
$pos = array_search($this->text[$i], $this->keys);
if($pos === false) {
// Search in extended?
$extended = $this->getExtendedVersion($this->text[$i]);
if($extended === false) {
$this->errorText .= 'Char \'' . $this->text[$i] . '\' not allowed.'."\n";
} else {
$extc = strlen($extended);
for($j = 0; $j < $extc; $j++) {
$v = $extended[$j];
if($v === '$') {
$indcheck[] = $this->EXTENDED_1;
$data[] = $this->code[$this->EXTENDED_1];
} elseif($v === '%') {
$indcheck[] = $this->EXTENDED_2;
$data[] = $this->code[$this->EXTENDED_2];
} elseif($v === '/') {
$indcheck[] = $this->EXTENDED_3;
$data[] = $this->code[$this->EXTENDED_3];
} elseif($v === '+') {
$indcheck[] = $this->EXTENDED_4;
$data[] = $this->code[$this->EXTENDED_4];
} else {
$pos2 = array_search($v, $this->keys);
$indcheck[] = $pos2;
$data[] = $this->code[$pos2];
}
}
}
} else {
$indcheck[] = $pos;
$data[] = $this->code[$pos];
}
}
$this->setData(array($indcheck, $data));
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
if(!empty($this->errorText)) {
$error = explode("\n", trim($this->errorText));
$c = count($error);
for($i = 0; $i < $c; $i++) {
$this->drawError($im, $error[$i]);
}
} else {
$c = count($this->data);
if($c === 0) {
$this->drawError($im, 'No text has been entered.');
} else {
// Starting *
$this->drawChar($im, $this->code[$this->starting], true);
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->data[$i], true);
}
// Checksum (rarely used)
if ($this->checksum === true) {
$this->drawChar($im, $this->code[$this->checksumValue % 43], true);
}
// Ending *
$this->drawChar($im, $this->code[$this->ending], true);
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$textlength = 13 * count($this->data) * $this->scale;
$startlength = 13 * $this->scale;
$checksumlength = 0;
if ($this->checksum === true) {
$checksumlength = 13 * $this->scale;
}
$endlength = 13 * $this->scale;
return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
$this->checksumValue = 0;
$c = count($this->indcheck);
for ($i = 0; $i < $c; $i++) {
$this->checksumValue += $this->indcheck[$i];
}
$this->checksumValue = $this->checksumValue % 43;
}
/**
* Saves data into the classes.
*
* This method will save data, calculate real column number
* (if -1 was selected), the real error level (if -1 was
* selected)... It will add Padding to the end and generate
* the error codes.
*
* @param array $data
*/
function setData($data) {
$this->indcheck = $data[0];
$this->data = $data[1];
$this->calculateChecksum();
}
function getExtendedVersion($char) {
$o = ord($char);
if($o === 0)
return '%U';
elseif($o >= 1 && $o <= 26)
return '$' . chr($o + 64);
elseif(($o >= 33 && $o <= 44) || $o === 47 || $o === 48)
return '/' . chr($o + 32);
elseif($o >= 97 && $o <= 122)
return '+' . chr($o - 32);
elseif($o >= 27 && $o <= 31)
return '%' . chr($o + 38);
elseif($o >= 59 && $o <= 63)
return '%' . chr($o + 11);
elseif($o >= 91 && $o <= 95)
return '%' . chr($o - 16);
elseif($o >= 123 && $o <= 127)
return '%' . chr($o - 43);
elseif($o === 64)
return '%V';
elseif($o === 96)
return '%W';
elseif($o > 127)
return false;
else
return $char;
}
};
?>

View File

@@ -0,0 +1,295 @@
<?php
/**
* BCGcode93.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - Code 93
*
* !! Warning !!
* If you display the checksum on the barcode, you may obtain
* some garbage since some characters are not displayable.
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3b 30 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGcode93.barcode.php,v 1.8 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.10
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGcode93 extends BCGBarcode1D {
var $EXTENDED_1 = 43; // const
var $EXTENDED_2 = 44; // const
var $EXTENDED_3 = 45; // const
var $EXTENDED_4 = 46; // const
var $starting, $ending;
var $indcheck, $data;
var $errorText;
/**
* Constructor
*/
function BCGcode93() { // public
BCGBarcode1D::BCGBarcode1D();
$this->starting = $this->ending = 47; /* * */
$this->keys = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','.',' ','$','/','+','%','($)','(%)','(/)','(+)','(*)');
$this->code = array(
'020001', /* 0 */
'000102', /* 1 */
'000201', /* 2 */
'000300', /* 3 */
'010002', /* 4 */
'010101', /* 5 */
'010200', /* 6 */
'000003', /* 7 */
'020100', /* 8 */
'030000', /* 9 */
'100002', /* A */
'100101', /* B */
'100200', /* C */
'110001', /* D */
'110100', /* E */
'120000', /* F */
'001002', /* G */
'001101', /* H */
'001200', /* I */
'011001', /* J */
'021000', /* K */
'000012', /* L */
'000111', /* M */
'000210', /* N */
'010011', /* O */
'020010', /* P */
'101001', /* Q */
'101100', /* R */
'100011', /* S */
'100110', /* T */
'110010', /* U */
'111000', /* V */
'001011', /* W */
'001110', /* X */
'011010', /* Y */
'012000', /* Z */
'010020', /* - */
'200001', /* . */
'200100', /* */
'210000', /* $ */
'001020', /* / */
'002010', /* + */
'100020', /* % */
'010110', /*($)*/
'201000', /*(%)*/
'200010', /*(/)*/
'011100', /*(+)*/
'000030' /*(*)*/
);
$this->errorText = '';
}
/**
* Saves Text
*
* @param string $text
*/
function parse($text) {
$this->text = $text;
$data = array();
$indcheck = array();
$this->errorText = ''; // Reset Error
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
$pos = array_search($this->text[$i], $this->keys);
if($pos === false) {
// Search in extended?
$extended = $this->getExtendedVersion($this->text[$i]);
if($extended === false) {
$this->errorText .= 'Char \'' . $this->text[$i] . '\' not allowed.'."\n";
} else {
$extc = strlen($extended);
for($j = 0; $j < $extc; $j++) {
$v = $extended[$j];
if($v === '$') {
$indcheck[] = $this->EXTENDED_1;
$data[] = $this->code[$this->EXTENDED_1];
} elseif($v === '%') {
$indcheck[] = $this->EXTENDED_2;
$data[] = $this->code[$this->EXTENDED_2];
} elseif($v === '/') {
$indcheck[] = $this->EXTENDED_3;
$data[] = $this->code[$this->EXTENDED_3];
} elseif($v === '+') {
$indcheck[] = $this->EXTENDED_4;
$data[] = $this->code[$this->EXTENDED_4];
} else {
$pos2 = array_search($v, $this->keys);
$indcheck[] = $pos2;
$data[] = $this->code[$pos2];
}
}
}
} else {
$indcheck[] = $pos;
$data[] = $this->code[$pos];
}
}
$this->setData(array($indcheck, $data));
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
if(!empty($this->errorText)) {
$error = explode("\n", trim($this->errorText));
$c = count($error);
for($i = 0; $i < $c; $i++) {
$this->drawError($im, $error[$i]);
}
} else {
$c = count($this->data);
if($c === 0) {
$this->drawError($im, 'No text has been entered.');
} else {
// Starting *
$this->drawChar($im, $this->code[$this->starting], true);
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->data[$i], true);
}
// Checksum
$c = count($this->checksumValue);
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->code[$this->checksumValue[$i]], true);
}
// Ending *
$this->drawChar($im, $this->code[$this->ending], true);
// Draw a Final Bar
$this->drawChar($im, '0', true);
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$startlength = 9 * $this->scale;
$textlength = 9 * count($this->data) * $this->scale;
$checksumlength = 2 * 9 * $this->scale;
$endlength = 9 * $this->scale + $this->scale; // + final bar
return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Checksum
// First CheckSUM "C"
// The "C" checksum character is the modulo 47 remainder of the sum of the weighted
// value of the data characters. The weighting value starts at "1" for the right-most
// data character, 2 for the second to last, 3 for the third-to-last, and so on up to 20.
// After 20, the sequence wraps around back to 1.
// Second CheckSUM "K"
// Same as CheckSUM "C" but we count the CheckSum "C" at the end
// After 15, the sequence wraps around back to 1.
$sequence_multiplier = array(20, 15);
$this->checksumValue = array();
$indcheck = $this->indcheck;
for($z = 0; $z < 2; $z++) {
$checksum = 0;
for($i = count($indcheck), $j = 0; $i > 0; $i--, $j++) {
$multiplier = $i % $sequence_multiplier[$z];
if($multiplier === 0) {
$multiplier = $sequence_multiplier[$z];
}
$checksum += $indcheck[$j] * $multiplier;
}
$this->checksumValue[$z] = $checksum % 47;
$indcheck[] = $this->checksumValue[$z];
}
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
$ret = '';
$c = count($this->checksumValue);
for($i = 0; $i < $c; $i++) {
$ret .= $this->keys[$this->checksumValue[$i]];
}
return $ret;
}
return false;
}
/**
* Saves data into the classes.
*
* This method will save data, calculate real column number
* (if -1 was selected), the real error level (if -1 was
* selected)... It will add Padding to the end and generate
* the error codes.
*
* @param array $data
*/
function setData($data) {
$this->indcheck = $data[0];
$this->data = $data[1];
$this->calculateChecksum();
}
function getExtendedVersion($char) {
$o = ord($char);
if($o === 0)
return '%U';
elseif($o >= 1 && $o <= 26)
return '$' . chr($o + 64);
elseif(($o >= 33 && $o <= 44) || $o === 47 || $o === 48)
return '/' . chr($o + 32);
elseif($o >= 97 && $o <= 122)
return '+' . chr($o - 32);
elseif($o >= 27 && $o <= 31)
return '%' . chr($o + 38);
elseif($o >= 59 && $o <= 63)
return '%' . chr($o + 11);
elseif($o >= 91 && $o <= 95)
return '%' . chr($o - 16);
elseif($o >= 123 && $o <= 127)
return '%' . chr($o - 43);
elseif($o === 64)
return '%V';
elseif($o === 96)
return '%W';
elseif($o > 127)
return false;
else
return $char;
}
};
?>

View File

@@ -0,0 +1,342 @@
<?php
/**
* BCGean13.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - EAN-13
*
* EAN-13 contains
* - 2 system digits (1 not displayed but coded with parity)
* - 5 manufacturer code digits
* - 5 product digits
* - 1 checksum digit
*
* The checksum is always displayed.
*
*--------------------------------------------------------------------
* Revision History
* v2.0.1 8 mar 2009 Jean-Sébastien Goupil Fix padding for the barcode
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.3.0 13 apr 2007 Jean-Sébastien Goupil Move ISBN implementation to isbn.php
* v1.2.3pl1 11 mar 2006 Jean-Sébastien Goupil Correct getMaxWidth if ISBN
* v1.2.3 6 feb 2006 Jean-Sébastien Goupil Fix label position + Using correctly static method
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.2 23 jul 2005 Jean-Sébastien Goupil Enhance rapidity
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGean13.barcode.php,v 1.14 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.13
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGean13 extends BCGBarcode1D {
var $codeParity = array();
/**
* Constructor
*/
function BCGean13() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
// Left-Hand Odd Parity starting with a space
// Left-Hand Even Parity is the inverse (0=0012) starting with a space
// Right-Hand is the same of Left-Hand starting with a bar
$this->code = array(
'2100', /* 0 */
'1110', /* 1 */
'1011', /* 2 */
'0300', /* 3 */
'0021', /* 4 */
'0120', /* 5 */
'0003', /* 6 */
'0201', /* 7 */
'0102', /* 8 */
'2001' /* 9 */
);
// Parity, 0=Odd, 1=Even for manufacturer code. Depending on 1st System Digit
$this->codeParity = array(
array(0,0,0,0,0), /* 0 */
array(0,1,0,1,1), /* 1 */
array(0,1,1,0,1), /* 2 */
array(0,1,1,1,0), /* 3 */
array(1,0,0,1,1), /* 4 */
array(1,1,0,0,1), /* 5 */
array(1,1,1,0,0), /* 6 */
array(1,0,1,0,1), /* 7 */
array(1,0,1,1,0), /* 8 */
array(1,1,0,1,0) /* 9 */
);
}
function parse($text) {
BCGBarcode1D::parse($text);
$this->setLabelOffset();
}
function setFont($font) {
BCGBarcode1D::setFont($font);
$this->setLabelOffset();
}
function setLabel($label) {
BCGBarcode1D::setLabel($label);
$this->setLabelOffset();
}
function setOffsetX($offsetX) {
BCGBarcode1D::setOffsetX($offsetX);
$this->setLabelOffset();
}
function setScale($scale) {
BCGBarcode1D::setScale($scale);
$this->setLabelOffset();
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
if($this->isCharsAllowed($im)) {
if($this->isLengthCorrect($im)) {
$this->drawBars($im);
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$startlength = 3 * $this->scale;
$centerlength = 5 * $this->scale;
$textlength = 12 * 7 * $this->scale;
$endlength = 3 * $this->scale;
return array($p[0] + $startlength + $centerlength + $textlength + $endlength, $p[1]);
}
function setLabelOffset() {
$label = $this->getLabel();
if(!empty($label)) {
if(is_a($this->textfont, 'BCGFont')) {
$f = $this->textfont; // clone
$f->setText(substr($label, 0, 1));
$val = ($f->getWidth() + 5) / $this->scale;
if($val > $this->offsetX) {
$this->offsetX = $val;
}
} elseif($this->textfont !== 0) {
$val = (imagefontwidth($this->textfont) + 2) / $this->scale;
if($val > $this->offsetX) {
$this->offsetX = $val;
}
}
}
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Calculating Checksum
// Consider the right-most digit of the message to be in an "odd" position,
// and assign odd/even to each character moving from right to left
// Odd Position = 3, Even Position = 1
// Multiply it by the number
// Add all of that and do 10-(?mod10)
$odd = true;
$this->checksumValue = 0;
$c = strlen($this->text);
for($i = $c; $i > 0; $i--) {
if($odd === true) {
$multiplier = 3;
$odd = false;
} else {
$multiplier = 1;
$odd = true;
}
if(!isset($this->keys[$this->text[$i - 1]])) {
return;
}
$this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier;
}
$this->checksumValue = (10 - $this->checksumValue % 10) % 10;
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
}
function isCharsAllowed(&$im) {
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
return false;
}
}
return true;
}
function isLengthCorrect(&$im) {
$c = strlen($this->text);
// If we have 13 chars just flush the last one
if($c === 13) {
$this->text = substr($this->text, 0, 12);
return true;
} elseif($c === 12) {
return true;
}
$this->drawError($im, 'Must provide 12 or 13 digits.');
return false;
}
function drawBars(&$im) {
// Checksum
$this->calculateChecksum();
$temp_text = $this->text . $this->keys[$this->checksumValue];
// Starting Code
$this->drawChar($im, '000', true);
// Draw Second Code
$this->drawChar($im, $this->findCode($temp_text[1]), false);
// Draw Manufacturer Code
for($i = 0; $i < 5; $i++) {
$this->drawChar($im, BCGean13::inverse($this->findCode($temp_text[$i + 2]), $this->codeParity[(int)$temp_text[0]][$i]), false);
}
// Draw Center Guard Bar
$this->drawChar($im, '00000', false);
// Draw Product Code
for($i = 7; $i < 13; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Draw Right Guard Bar
$this->drawChar($im, '000', true);
}
/**
* Overloaded method for drawing special label
*
* @param resource $im
*/
function drawText(&$im) {
if($this->label !== $this->AUTO_LABEL) {
BCGBarcode1D::drawText($im);
} elseif($this->label !== '') {
$temp_text = $this->text . $this->keys[$this->checksumValue];
if (is_a($this->textfont, 'BCGFont')) {
$code1 = 0;
$code2 = 0;
$this->textfont->setText($temp_text);
$this->drawExtendedBars($im, $this->textfont->getHeight(), $code1, $code2);
// We need to separate the text, one on the left and one on the right and one starting
$text0 = substr($temp_text, 0, 1);
$text1 = substr($temp_text, 1, 6);
$text2 = substr($temp_text, 7, 6);
$font0 = $this->textfont; // clone
$font1 = $this->textfont; // clone
$font2 = $this->textfont; // clone
$font0->setText($text0);
$font1->setText($text1);
$font2->setText($text2);
$xPosition0 = $this->offsetX * $this->scale - $font0->getWidth() - 4; // -4 is just for beauty
$yPosition0 = $this->thickness * $this->scale + $font0->getHeight() / 2 + $this->offsetY * $this->scale;
$xPosition1 = ($this->scale * 44 - $font1->getWidth()) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale;
$xPosition2 = ($this->scale * 44 - $font1->getWidth()) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $this->textfont->getHeight() + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale;
$text_color = $this->colorFg->allocate($im);
$font0->draw($im, $text_color, $xPosition0, $yPosition0);
$font1->draw($im, $text_color, $xPosition1, $yPosition);
$font2->draw($im, $text_color, $xPosition2, $yPosition);
} elseif($this->textfont !== 0) {
$code1 = 0;
$code2 = 0;
$this->drawExtendedBars($im, 9, $code1, $code2);
$startPosition = 10;
$xPosition0 = $this->offsetX * $this->scale - imagefontwidth($this->textfont);
$yPosition0 = $this->thickness * $this->scale - imagefontheight($this->textfont) / 2 + $this->offsetY * $this->scale;
$xPosition1 = ($this->scale * 44 - imagefontwidth($this->textfont) * 6) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale;
$xPosition2 = ($this->scale * 44 - imagefontwidth($this->textfont) * 6) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + 1 * $this->scale + $this->offsetY * $this->scale;
$text_color = $this->colorFg->allocate($im);
imagechar($im, $this->textfont, $xPosition0, $yPosition0, $temp_text[0], $text_color);
imagestring($im, $this->textfont, $xPosition1, $yPosition, substr($temp_text, 1, 6), $text_color);
imagestring($im, $this->textfont, $xPosition2, $yPosition, substr($temp_text, 7, 6), $text_color);
}
}
}
function drawExtendedBars(&$im, $plus, &$code1, &$code2) {
$rememberX = $this->positionX;
$rememberH = $this->thickness;
// We increase the bars
$this->thickness = $this->thickness + ceil($plus / $this->scale);
$this->positionX = 0;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->drawSingleBar($im, $this->COLOR_FG);
$code1 = $this->positionX;
// Center Guard Bar
$this->positionX += 44;
$this->DrawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->DrawSingleBar($im, $this->COLOR_FG);
// Last Bars
$code2 = $this->positionX;
$this->positionX += 44;
$this->DrawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->DrawSingleBar($im, $this->COLOR_FG);
$this->positionX = $rememberX;
$this->thickness = $rememberH;
}
function inverse($text, $inverse = 1) { // static
if($inverse === 1) {
$text = strrev($text);
}
return $text;
}
};
?>

View File

@@ -0,0 +1,238 @@
<?php
/**
* BCGean8.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - EAN-8
*
* EAN-8 contains
* - 4 digits
* - 3 digits
* - 1 checksum
*
* The checksum is always displayed.
*
*--------------------------------------------------------------------
* Revision History
* v2.0.1 8 mar 2009 Jean-Sébastien Goupil Fix padding for the barcode
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3 6 feb 2006 Jean-Sébastien Goupil Fix label position
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.2 23 jul 2005 Jean-Sébastien Goupil Enhance rapidity
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGean8.barcode.php,v 1.11 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.12
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGean8 extends BCGBarcode1D {
/**
* Constructor
*/
function BCGean8() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
// Left-Hand Odd Parity starting with a space
// Right-Hand is the same of Left-Hand starting with a bar
$this->code = array(
'2100', /* 0 */
'1110', /* 1 */
'1011', /* 2 */
'0300', /* 3 */
'0021', /* 4 */
'0120', /* 5 */
'0003', /* 6 */
'0201', /* 7 */
'0102', /* 8 */
'2001' /* 9 */
);
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Must contain 7 chars
if($c !== 7) {
$this->drawError($im, 'Must contain 7 chars, the 8th digit is automatically added.');
$error_stop = true;
}
if($error_stop === false) {
// Checksum
$this->calculateChecksum();
$temp_text = $this->text . $this->keys[$this->checksumValue];
// Starting Code
$this->drawChar($im, '000', true);
// Draw First 4 Chars (Left-Hand)
for($i = 0; $i < 4; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), false);
}
// Draw Center Guard Bar
$this->drawChar($im, '00000', false);
// Draw Last 4 Chars (Right-Hand)
for($i = 4; $i < 8; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Draw Right Guard Bar
$this->drawChar($im, '000', true);
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$startlength = 3 * $this->scale;
$centerlength = 5 * $this->scale;
$textlength = 8 * 7 * $this->scale;
$endlength = 3 * $this->scale;
return array($p[0] + $startlength + $centerlength + $textlength + $endlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Calculating Checksum
// Consider the right-most digit of the message to be in an "odd" position,
// and assign odd/even to each character moving from right to left
// Odd Position = 3, Even Position = 1
// Multiply it by the number
// Add all of that and do 10-(?mod10)
$odd = true;
$this->checksumValue = 0;
$c = strlen($this->text);
for($i = $c; $i > 0; $i--) {
if($odd === true) {
$multiplier = 3;
$odd = false;
} else {
$multiplier = 1;
$odd = true;
}
if(!isset($this->keys[$this->text[$i - 1]])) {
return;
}
$this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier;
}
$this->checksumValue = (10 - $this->checksumValue % 10) % 10;
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
}
/**
* Overloaded method for drawing special label
*
* @param resource $im
*/
function drawText(&$im) {
if($this->label !== $this->AUTO_LABEL) {
BCGBarcode1D::drawText($im);
} elseif($this->label !== '') {
$temp_text = $this->text . $this->keys[$this->checksumValue];
if(is_a($this->textfont, 'BCGFont')) {
$code1 = 0;
$code2 = 0;
$this->textfont->setText($temp_text);
$this->drawExtendedBars($im, $this->textfont->getHeight(), $code1, $code2);
// We need to separate the text, one on the left and one on the right
$text1 = substr($temp_text, 0, 4);
$text2 = substr($temp_text, 4, 4);
$font1 = $this->textfont; // clone
$font2 = $this->textfont; // clone
$font1->setText($text1);
$font2->setText($text2);
// The $this->res offset is to center without thinking of the white space in the guard
$xPosition1 = ($this->scale * 30 - $font1->getWidth()) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale;
$xPosition2 = ($this->scale * 30 - $font2->getWidth()) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $this->textfont->getHeight() + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale;
$text_color = $this->colorFg->allocate($im);
$font1->draw($im, $text_color, $xPosition1, $yPosition);
$font2->draw($im, $text_color, $xPosition2, $yPosition);
} elseif($this->textfont !== 0) {
$code1 = 0;
$code2 = 0;
$this->drawExtendedBars($im, 9, $code1, $code2);
$xPosition1 = ($this->scale * 30 - imagefontwidth($this->textfont) * 4) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale;
$xPosition2 = ($this->scale * 30 - imagefontwidth($this->textfont) * 4) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + 1 * $this->scale + $this->offsetY * $this->scale;
$text_color = $this->colorFg->allocate($im);
imagestring($im, $this->textfont, $xPosition1, $yPosition, substr($temp_text, 0, 4), $text_color);
imagestring($im, $this->textfont, $xPosition2, $yPosition, substr($temp_text, 4, 4), $text_color);
}
}
}
function drawExtendedBars(&$im, $plus, &$code1, &$code2) {
$rememberX = $this->positionX;
$rememberH = $this->thickness;
// We increase the bars
$this->thickness = $this->thickness + ceil($plus / $this->scale);
$this->positionX = 0;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->drawSingleBar($im, $this->COLOR_FG);
$code1 = $this->positionX;
// Center Guard Bar
$this->positionX += 30;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->drawSingleBar($im, $this->COLOR_FG);
// Last Bars
$code2 = $this->positionX;
$this->positionX += 30;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX = $rememberX;
$this->thickness = $rememberH;
}
};
?>

View File

@@ -0,0 +1,592 @@
<?php
/**
* BCGgs1128.barcode.php
*--------------------------------------------------------------------
*
* Calculate the GS1-128 based on the Code-128 encoding.
*
*--------------------------------------------------------------------
* Revision History
* V2.2.0 10 feb 2010 Kevin Gilbert, reviewed by Jean-Sébastien Goupil, new version
*--------------------------------------------------------------------
* $Id: BCGgs1128.barcode.php,v 1.1 2010/02/14 00:25:14 jsgoupil Exp $<
* PHP5-Revision: 1.1
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGcode128.barcode.php');
class BCGgs1128 extends BCGcode128 {
var $KIND_OF_DATA = 0; // const
var $MINLENGTH = 1; // const
var $MAXLENGTH = 2; // const
var $CHECKSUM = 3; // const
var $NUMERIC = 0; // const
var $ALPHA_NUMERIC = 1; // const
var $DATE_YYMMDD = 2; // const
var $ID = 0; // const
var $CONTENT = 1; // const
var $MAX_ID_FORMATED = 6; // const
var $MAX_ID_NOT_FORMATED = 4; // const
var $MAX_GS1128_CHARS = 48; // const
var $errorTextGS1128;
var $strictMode;
var $identifiersId = array();
var $identifiersContent = array();
var $identifiersAi = array();
/**
* Constructor
*
* @param char $start
*/
function BCGgs1128($start = NULL) { // public
if($start === NULL) {
$start = 'C';
}
BCGcode128::BCGcode128($start);
/* Application Identifiers (AIs) */
/*
array ( KIND_OF_DATA , MINLENGTH , MAXLENGTH , CHECKSUM )
KIND_OF_DATA: NUMERIC , ALPHA_NUMERIC or DATE_YYMMDD
CHECKSUM: bool (true / false)
*/
$this->identifiersAi = array(
'00' => array($this->NUMERIC, 18, 18, true),
'01' => array($this->NUMERIC, 14, 14, true),
'02' => array($this->NUMERIC, 14, 14, true),
'10' => array($this->ALPHA_NUMERIC, 1, 20, false),
'11' => array($this->DATE_YYMMDD, 6, 6, false),
'12' => array($this->DATE_YYMMDD, 6, 6, false),
'13' => array($this->DATE_YYMMDD, 6, 6, false),
'15' => array($this->DATE_YYMMDD, 6, 6, false),
'17' => array($this->DATE_YYMMDD, 6, 6, false),
'20' => array($this->NUMERIC, 2, 2, false),
'21' => array($this->ALPHA_NUMERIC, 1, 20, false),
'240' => array($this->ALPHA_NUMERIC, 1, 30, false),
'241' => array($this->ALPHA_NUMERIC, 1, 30, false),
'250' => array($this->ALPHA_NUMERIC, 1, 30, false),
'251' => array($this->ALPHA_NUMERIC, 1, 30, false),
'253' => array($this->NUMERIC, 14, 30, false),
'30' => array($this->NUMERIC, 1, 8, false),
'310y' => array($this->NUMERIC, 6, 6, false),
'311y' => array($this->NUMERIC, 6, 6, false),
'312y' => array($this->NUMERIC, 6, 6, false),
'313y' => array($this->NUMERIC, 6, 6, false),
'314y' => array($this->NUMERIC, 6, 6, false),
'315y' => array($this->NUMERIC, 6, 6, false),
'316y' => array($this->NUMERIC, 6, 6, false),
'320y' => array($this->NUMERIC, 6, 6, false),
'321y' => array($this->NUMERIC, 6, 6, false),
'322y' => array($this->NUMERIC, 6, 6, false),
'323y' => array($this->NUMERIC, 6, 6, false),
'324y' => array($this->NUMERIC, 6, 6, false),
'325y' => array($this->NUMERIC, 6, 6, false),
'326y' => array($this->NUMERIC, 6, 6, false),
'327y' => array($this->NUMERIC, 6, 6, false),
'328y' => array($this->NUMERIC, 6, 6, false),
'329y' => array($this->NUMERIC, 6, 6, false),
'330y' => array($this->NUMERIC, 6, 6, false),
'331y' => array($this->NUMERIC, 6, 6, false),
'332y' => array($this->NUMERIC, 6, 6, false),
'333y' => array($this->NUMERIC, 6, 6, false),
'334y' => array($this->NUMERIC, 6, 6, false),
'335y' => array($this->NUMERIC, 6, 6, false),
'336y' => array($this->NUMERIC, 6, 6, false),
'337y' => array($this->NUMERIC, 6, 6, false),
'340y' => array($this->NUMERIC, 6, 6, false),
'341y' => array($this->NUMERIC, 6, 6, false),
'342y' => array($this->NUMERIC, 6, 6, false),
'343y' => array($this->NUMERIC, 6, 6, false),
'344y' => array($this->NUMERIC, 6, 6, false),
'345y' => array($this->NUMERIC, 6, 6, false),
'346y' => array($this->NUMERIC, 6, 6, false),
'347y' => array($this->NUMERIC, 6, 6, false),
'348y' => array($this->NUMERIC, 6, 6, false),
'349y' => array($this->NUMERIC, 6, 6, false),
'350y' => array($this->NUMERIC, 6, 6, false),
'351y' => array($this->NUMERIC, 6, 6, false),
'352y' => array($this->NUMERIC, 6, 6, false),
'353y' => array($this->NUMERIC, 6, 6, false),
'354y' => array($this->NUMERIC, 6, 6, false),
'355y' => array($this->NUMERIC, 6, 6, false),
'356y' => array($this->NUMERIC, 6, 6, false),
'357y' => array($this->NUMERIC, 6, 6, false),
'360y' => array($this->NUMERIC, 6, 6, false),
'361y' => array($this->NUMERIC, 6, 6, false),
'362y' => array($this->NUMERIC, 6, 6, false),
'363y' => array($this->NUMERIC, 6, 6, false),
'364y' => array($this->NUMERIC, 6, 6, false),
'365y' => array($this->NUMERIC, 6, 6, false),
'366y' => array($this->NUMERIC, 6, 6, false),
'367y' => array($this->NUMERIC, 6, 6, false),
'368y' => array($this->NUMERIC, 6, 6, false),
'369y' => array($this->NUMERIC, 6, 6, false),
'37' => array($this->NUMERIC, 1, 8, false),
'390y' => array($this->NUMERIC, 1, 15, false),
'391y' => array($this->NUMERIC, 4, 18, false),
'392y' => array($this->NUMERIC, 1, 15, false),
'393y' => array($this->NUMERIC, 4, 18, false),
'400' => array($this->ALPHA_NUMERIC, 1, 30, false),
'401' => array($this->ALPHA_NUMERIC, 1, 30, false),
'402' => array($this->NUMERIC, 17, 17, false),
'403' => array($this->ALPHA_NUMERIC, 1, 30, false),
'410' => array($this->NUMERIC, 13, 13, true),
'411' => array($this->NUMERIC, 13, 13, true),
'412' => array($this->NUMERIC, 13, 13, true),
'413' => array($this->NUMERIC, 13, 13, true),
'414' => array($this->NUMERIC, 13, 13, true),
'415' => array($this->NUMERIC, 13, 13, true),
'420' => array($this->ALPHA_NUMERIC, 1, 20, false),
'421' => array($this->ALPHA_NUMERIC, 4, 12, false),
'422' => array($this->NUMERIC, 3, 3, false),
'8001' => array($this->NUMERIC, 14, 14, false),
'8002' => array($this->ALPHA_NUMERIC, 1, 20, false),
'8003' => array($this->ALPHA_NUMERIC, 15, 30, false),
'8004' => array($this->ALPHA_NUMERIC, 1, 30, false),
'8005' => array($this->NUMERIC, 6, 6, false),
'8006' => array($this->NUMERIC, 18, 18, false),
'8007' => array($this->ALPHA_NUMERIC, 1, 30, false),
'8018' => array($this->NUMERIC, 18, 18, false),
'8020' => array($this->ALPHA_NUMERIC, 1, 25, false),
'8100' => array($this->NUMERIC, 6, 6, false),
'8101' => array($this->NUMERIC, 10, 10, false),
'8102' => array($this->NUMERIC, 2, 2, false),
'90' => array($this->ALPHA_NUMERIC, 1, 30, false),
'91' => array($this->ALPHA_NUMERIC, 1, 30, false),
'92' => array($this->ALPHA_NUMERIC, 1, 30, false),
'93' => array($this->ALPHA_NUMERIC, 1, 30, false),
'94' => array($this->ALPHA_NUMERIC, 1, 30, false),
'95' => array($this->ALPHA_NUMERIC, 1, 30, false),
'96' => array($this->ALPHA_NUMERIC, 1, 30, false),
'97' => array($this->ALPHA_NUMERIC, 1, 30, false),
'98' => array($this->ALPHA_NUMERIC, 1, 30, false),
'99' => array($this->ALPHA_NUMERIC, 1, 30, false)
);
$this->setStrictMode(true);
$this->setTilde(true);
}
/**
* Enables or disables the strict mode
*
* @param bool strictMode
*/
function setStrictMode($strictMode) { // public
$this->strictMode = $strictMode;
}
/**
* Parses Text
*
* @param string $text
*/
function parse($text) { // public
parent::parse($this->parseGs1128($text));
$this->errorText .= $this->errorTextGS1128;
}
/**
* Formats data for gs1-128
*
* @return string
*/
function formatGs1128() { // private
$formatedText = '~F1';
$formatedLabel = '';
$c = count($this->identifiersId);
for($i = 0; $i < $c; $i++) {
if($i > 0) {
$formatedLabel .= ' ';
}
$formatedLabel .= '(' . $this->identifiersId[$i] . ')';
$formatedText .= $this->identifiersId[$i];
$formatedLabel .= $this->identifiersContent[$i];
$formatedText .= $this->identifiersContent[$i];
if(isset($this->identifiersAi[$this->identifiersId[$i]])) {
$ai_data = $this->identifiersAi[$this->identifiersId[$i]];
} elseif(isset($this->identifiersId[$i][3])) {
$identifierWithVar = substr($this->identifiersId[$i], 0, -1) . 'y';
$ai_data = isset($this->identifiersAi[$identifierWithVar]) ? $this->identifiersAi[$identifierWithVar] : NULL;
} else {
$ai_data = NULL;
}
/* We'll check if we need to add a ~F1 (<GS>) char */
/* If we use the legacy mode, we always add a ~F1 (<GS>) char between AIs */
if($ai_data !== NULL) {
if(strlen($this->identifiersContent[$i]) < $ai_data[$this->MAXLENGTH] && ($i + 1) !== $c || !$this->strictMode && ($i + 1) !== $c) {
$formatedText .= '~F1';
}
}
}
if((strlen($formatedText) - 3) > $this->MAX_GS1128_CHARS) {
$this->errorTextGS1128 = 'The barcode can\'t be bigger than ' . $this->MAX_GS1128_CHARS . ' characters.';
}
$this->label = $formatedLabel;
return $formatedText;
}
/**
* Parses the text to gs1-128
*
* @param mixed $text
* @return mixed
*/
function parseGs1128($text) { // private
/* We format correctly what the user gives */
if(is_array($text)) {
$formatArray = array();
foreach($text as $content) {
if(is_array($content)) { /* double array */
if(count($content) === 2) {
if(is_array($content[$this->ID]) || is_array($content[$this->CONTENT])) {
$this->errorTextGS1128 = 'Double arrays can\'t contain arrays.';
return false;
} else {
$formatArray[] = '(' . $content[$this->ID] . ')' . $content[$this->CONTENT];
}
} else {
$this->errorTextGS1128 = 'Double arrays must contain 2 values.';
return false;
}
} else { /* simple array */
$formatArray[] = $content;
}
}
unset($text);
$text = $formatArray;
} else { /* string */
$text = array($text);
}
$textCount = count($text);
for($cmpt = 0; $cmpt < $textCount; $cmpt++) {
/* We parse the content of the array */
if(!$this->parseContent($text[$cmpt])) {
return false;
}
}
return $this->formatGs1128();
}
/**
* Splits the id and the content for each application identifiers (AIs)
*
* @param string $text
* @param int $cmpt
*
* @return bool
*/
function parseContent($text) { // private
/* $yAlreadySet has 3 states: */
/* null: There is no variable in the ID; true: the variable is already set; false: the variable is not set yet; */
$yAlreadySet = NULL;
$realNameId = NULL;
$separatorsFound = 0;
$checksumAdded = 0;
$decimalPointRemoved = 0;
$toParse = str_replace('~F1' ,chr(29), $text);
$nbCharToParse = strlen($toParse);
$isFormated = $toParse[0] === '(' ? true : false;
$maxCharId = $isFormated ? $this->MAX_ID_FORMATED : $this->MAX_ID_NOT_FORMATED;
$id = strtolower(substr($toParse, 0, min($maxCharId, $nbCharToParse)));
$id = $isFormated ? $this->findIdFormated($id, $yAlreadySet, $realNameId) : $this->findIdNotFormated($id, $yAlreadySet, $realNameId);
if($id === false) {
return false;
}
$nbCharId = $isFormated ? strlen($id) + 2 : strlen($id);
$n = min($this->identifiersAi[$realNameId][$this->MAXLENGTH], $nbCharToParse);
$content = substr($toParse, $nbCharId, $n);
/* If we have an AI with an "y" var, we check if there is a decimal point in the next *MAXLENGTH* characters */
/* if there is one, we take an extra character */
if($yAlreadySet !== NULL) {
if(strpos($content, '.') !== false || strpos($content, ',') !== false) {
$n++;
if($n <= $nbCharToParse) {
/* We take an extra char */
$content = substr($toParse, $nbCharId, $n);
}
}
}
/* We check for separator */
$separator = strpos($content, chr(29));
if($separator !== false) {
$content = substr($content, 0, $separator);
$separatorsFound++;
}
/* We check the conformity */
if(!$this->checkConformity($content, $id, $realNameId)) {
return false;
}
/* We check the checksum */
if(!$this->checkChecksum($content, $id, $realNameId, $checksumAdded)) {
return false;
}
/* We check the vars */
if(!$this->checkVars($content, $id, $yAlreadySet, $decimalPointRemoved)) {
return false;
}
$this->identifiersId[] = $id;
$this->identifiersContent[] = $content;
$nbCharLastContent = (((strlen($content) + $nbCharId) - $checksumAdded) + $decimalPointRemoved) + $separatorsFound;
if($nbCharToParse - $nbCharLastContent > 0) {
/* If there is more than one content in this array, we parse again */
$otherContent = substr($toParse, $nbCharLastContent, $nbCharToParse);
$nbCharOtherContent = strlen($otherContent);
if($otherContent[0] === chr(29)) {
$otherContent = substr($otherContent, 1);
$nbCharOtherContent--;
}
if($nbCharOtherContent > 0) {
$text = $otherContent;
$this->parseContent($text);
}
}
return true;
}
/**
* Checks if an id exists
*
* @param string $id
* @param bool $yAlreadySet
* @param string $realNameId
*
* @return bool
*/
function idExists($id, &$yAlreadySet, &$realNameId) { // private
$yFound = isset($id[3]) && $id[3] === 'y';
$idVarAdded = substr($id, 0, -1) . 'y';
if(isset($this->identifiersAi[$id])) {
if($yFound) {
$yAlreadySet = false;
}
$realNameId = $id;
return true;
} elseif(!$yFound && isset($this->identifiersAi[$idVarAdded])) {
/* if the id don't exist, we try to find this id with "y" at the last char */
$yAlreadySet = true;
$realNameId = $idVarAdded;
return true;
}
return false;
}
/**
* Finds ID with formated content
*
* @param string $id
* @param bool $yAlreadySet
* @param string $realNameId
* @return mixed
*/
function findIdFormated($id, &$yAlreadySet, &$realNameId) { // private
$pos = strpos($id, ')');
if($pos === false) {
$this->errorTextGS1128 = 'Identifiers must have no more than 4 characters.';
return false;
} else {
if($pos < 3) {
$this->errorTextGS1128 = 'Identifiers must have at least 2 characters.';
return false;
}
$id = substr($id, 1, $pos - 1);
if($this->idExists($id, $yAlreadySet, $realNameId)) {
return $id;
} else {
$this->errorTextGS1128 = 'The identifier ' . $id . ' doesn\'t exist.';
return false;
}
}
}
/**
* Finds ID with non-formated content
*
* @param string $id
* @param bool $yAlreadySet
* @param string $realNameId
* @return mixed
*/
function findIdNotFormated($id, &$yAlreadySet, &$realNameId) { // private
$tofind = $id;
while(strlen($tofind) >= 2) {
if($this->idExists($tofind, $yAlreadySet, $realNameId)) {
return $tofind;
} else {
$tofind = substr($tofind, 0, -1);
}
}
$this->errorTextGS1128 = 'Error in formatting, can\'t find an identifier.';
return false;
}
/**
* Checks confirmity of the content
*
* @param string $content
* @param string $id
* @param string $realNameId
* @return bool
*/
function checkConformity(&$content, $id, $realNameId) { // private
switch($this->identifiersAi[$realNameId][$this->KIND_OF_DATA]) {
case $this->NUMERIC:
$content = str_replace(',', '.', $content);
if(!preg_match("/^[0-9.]+$/", $content)) {
$this->errorTextGS1128 = 'The value of "' . $id . '" must be numerical.';
return false;
}
break;
case $this->DATE_YYMMDD:
$valid_date = true;
if(preg_match("/^[0-9]{6}$/", $content)) {
$year = substr($content, 0, 2);
$month = substr($content, 2, 2);
$day = substr($content, 4, 2);
/* day can be 00 if we only need month and year */
if(intval($month) < 1 || intval($month) > 12 || intval($day) < 0 || intval($day) > 31) {
$valid_date = false;
}
} else {
$valid_date = false;
}
if(!$valid_date) {
$this->errorTextGS1128 = 'The value of "' . $id . '" must be in YYMMDD format.';
return false;
}
break;
}
/* We check the length of the content */
$nbCharContent = strlen($content);
$checksumChar = 0;
$minlengthContent = $this->identifiersAi[$realNameId][$this->MINLENGTH];
$maxlengthContent = $this->identifiersAi[$realNameId][$this->MAXLENGTH];
if($this->identifiersAi[$realNameId][$this->CHECKSUM]) {
$checksumChar++;
}
if($nbCharContent < ($minlengthContent - $checksumChar)) {
if($minlengthContent === $maxlengthContent) {
$this->errorTextGS1128 = 'The value of "' . $id . '" must contain ' . $minlengthContent . ' character(s).';
return false;
} else {
$this->errorTextGS1128 = 'The value of "' . $id . '" must contain between ' . $minlengthContent . ' and ' . $maxlengthContent . ' character(s).';
return false;
}
}
return true;
}
/**
* Verifies the checksum
*
* @param string $content
* @param string $id
* @param int $realNameId
* @param int $checksumAdded
* @return bool
*/
function checkChecksum(&$content, $id, $realNameId, &$checksumAdded) { // private
if($this->identifiersAi[$realNameId][$this->CHECKSUM]) {
$nbCharContent = strlen($content);
$minlengthContent = $this->identifiersAi[$realNameId][$this->MINLENGTH];
if($nbCharContent === ($minlengthContent - 1)) {
/* we need to calculate the checksum */
$content .= $this->calculateChecksumMod10($content);
$checksumAdded++;
} elseif($nbCharContent === $minlengthContent) {
/* we need to check the checksum */
$checksum = $this->calculateChecksumMod10(substr($content, 0, -1));
if(intval($content[$nbCharContent - 1]) !== $checksum) {
$this->errorTextGS1128 = 'The checksum of "(' . $id . ') ' . $content . '" must be: ' . $checksum;
return false;
}
}
}
return true;
}
/**
* Checks vars "y"
*
* @param string $content
* @param string $id
* @param bool $yAlreadySet
* @param int $decimalPointRemoved
* @return bool
*/
function checkVars(&$content, &$id, $yAlreadySet, &$decimalPointRemoved) { // private
$nbCharContent = strlen($content);
/* We check for "y" var in AI */
if($yAlreadySet) {
/* We'll check if we have a decimal point */
if(strpos($content, '.') !== false) {
$this->errorTextGS1128 = 'If you do not use any "y" variable, you have to insert a whole number.';
return false;
}
} elseif($yAlreadySet !== NULL) {
/* We need to replace the "y" var with the position of the decimal point */
$pos = strpos($content, '.');
if($pos === false) {
$this->errorTextGS1128 = 'If you use a "y" variable, you have to insert a decimal number.';
return false;
} else {
$id = str_replace('y', $nbCharContent - ($pos + 1), strtolower($id));
$content = str_replace('.', '', $content);
$decimalPointRemoved++;
}
}
return true;
}
/**
* Checksum Mod10
* @param int $content
* @return int
*/
function calculateChecksumMod10($content) { // private
// Calculating Checksum
// Consider the right-most digit of the message to be in an "odd" position,
// and assign odd/even to each character moving from right to left
// Odd Position = 3, Even Position = 1
// Multiply it by the number
// Add all of that and do 10-(?mod10)
$odd = true;
$checksumValue = 0;
$c = strlen($content);
for($i = $c; $i > 0; $i--) {
if($odd === true) {
$multiplier = 3;
$odd = false;
} else {
$multiplier = 1;
$odd = true;
}
$checksumValue += ($content[$i - 1] * $multiplier);
}
return (10 - $checksumValue % 10) % 10;
}
};
?>

View File

@@ -0,0 +1,164 @@
<?php
/**
* BCGi25.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - Interleaved 2 of 5
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.2 23 jul 2005 Jean-Sébastien Goupil Correct Checksum
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGi25.barcode.php,v 1.8 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.10
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGi25 extends BCGBarcode1D {
var $checksum;
/**
* Constructor
*/
function BCGi25() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
$this->code = array(
'00110', /* 0 */
'10001', /* 1 */
'01001', /* 2 */
'11000', /* 3 */
'00101', /* 4 */
'10100', /* 5 */
'01100', /* 6 */
'00011', /* 7 */
'10010', /* 8 */
'01010' /* 9 */
);
$this->setChecksum(false);
}
function setChecksum($checksum) {
$this->checksum = (bool)$checksum;
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Must be even
if($c % 2 !== 0 && $this->checksum === false) {
$this->drawError($im, 'i25 must be even if checksum is false.');
$error_stop = true;
} elseif($c % 2 === 0 && $this->checksum === true) {
$this->drawError($im, 'i25 must be odd if checksum is true.');
$error_stop = true;
}
if($error_stop === false) {
$temp_text = $this->text;
// Checksum
if($this->checksum === true) {
$this->calculateChecksum();
$temp_text .= $this->keys[$this->checksumValue];
}
// Starting Code
$this->drawChar($im, '0000', true);
// Chars
$c = strlen($temp_text);
for($i = 0; $i < $c; $i += 2) {
$temp_bar = '';
$c2 = strlen($this->findCode($temp_text[$i]));
for($j = 0; $j < $c2; $j++) {
$temp_bar .= substr($this->findCode($temp_text[$i]), $j, 1);
$temp_bar .= substr($this->findCode($temp_text[$i + 1]), $j, 1);
}
$this->drawChar($im, $temp_bar, true);
}
// Ending Code
$this->drawChar($im, '100', true);
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$textlength = 7 * strlen($this->text) * $this->scale;
$startlength = 4 * $this->scale;
$checksumlength = 0;
if($this->checksum === true) {
$checksumlength = 7 * $this->scale;
}
$endlength = 4 * $this->scale;
return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Calculating Checksum
// Consider the right-most digit of the message to be in an "even" position,
// and assign odd/even to each character moving from right to left
// Even Position = 3, Odd Position = 1
// Multiply it by the number
// Add all of that and do 10-(?mod10)
$even = true;
$this->checksumValue = 0;
$c = strlen($this->text);
for($i = $c; $i > 0; $i--) {
if($even === true) {
$multiplier = 3;
$even = false;
} else {
$multiplier = 1;
$even = true;
}
$this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier;
}
$this->checksumValue = (10 - $this->checksumValue % 10) % 10;
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
}
};
?>

View File

@@ -0,0 +1,268 @@
<?php
/**
* BCGisbn.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - ISBN-10 and ISBN-13
*
* You can provide an ISBN with 10 digits with or without the checksum.
* You can provide an ISBN with 13 digits with or without the checksum.
* Calculate the ISBN based on the EAN-13 encoding.
*
* The checksum is always displayed.
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.5 13 apr 2007 Jean-Sébastien Goupil
*--------------------------------------------------------------------
* $Id: BCGisbn.barcode.php,v 1.6 2010/02/14 00:25:14 jsgoupil Exp $
* PHP5-Revision: 1.7
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGean13.barcode.php');
class BCGisbn extends BCGean13 {
var $GS1_AUTO = 0; // const
var $GS1_PREFIX978 = 1; // const
var $GS1_PREFIX979 = 2; // const
var $gs1;
var $isbn_created;
var $isbn_text;
var $isbn_textfont;
var $forceOffsetY;
/**
* Constructor
*
* @param int $gs1
* @param string $isbn_text
* @param mixed $textfont2 BCGFont or int
*/
function BCGisbn($gs1 = 0, $isbn_text = '##!!AUTO_LABEL!!##', $isbn_font = null) {
BCGean13::BCGean13();
$this->forceOffsetY = false;
$this->setISBNFont($isbn_font);
$this->setISBNText($isbn_text);
$this->setGS1($gs1);
}
/**
* Saves Text
*
* @param string $text
*/
function parse($text) {
BCGBarcode1D::parse(str_replace(array('-', ' '), '', $text));
$this->createISBNText();
$this->setLabelOffset();
}
/**
* Sets the first numbers of the barcode.
* - GS1_AUTO: Adds 978 before the code
* - GS1_PREFIX978: Adds 978 before the code
* - GS1_PREFIX979: Adds 979 before the code
*
* @param int $gs1
*/
function setGS1($gs1) {
$gs1 = (int)$gs1;
if($gs1 !== $this->GS1_AUTO && $gs1 !== $this->GS1_PREFIX978 && $gs1 !== $this->GS1_PREFIX979) {
$gs1 = $this->GS1_AUTO;
}
$this->gs1 = $gs1;
}
/**
* Sets the font to write the ISBN text on the top of the barcode.
*
* @param mixed $font
*/
function setISBNFont($font) {
if(is_a($font, 'BCGFont')) {
$this->isbn_textfont = $font; // clone
} else if($font === null) {
$this->isbn_textfont = null;
} else {
$this->isbn_textfont = intval($font);
}
$this->setLabelOffset();
}
/**
* Sets the text for the ISBN value.
*
* @param string $isbn_text
*/
function setISBNText($text) {
$this->isbn_text = $text;
$this->createISBNText();
$this->setLabelOffset();
}
function setOffsetY($offsetY) {
BCGean13::setOffsetY($offsetY);
// We force the offsetY, so we won't position based on the label position
$this->forceOffsetY = true;
}
function getMaxSize() {
// We must compute the first digit calculating the width
$null = null;
$this->isLengthCorrect($null);
return BCGean13::getMaxSize();
}
function setLabelOffset() {
BCGean13::setLabelOffset();
if(!empty($this->isbn_created) && !$this->forceOffsetY) {
if(is_a($this->getISBNFont(), 'BCGFont')) {
$f = $this->getISBNFont(); // clone
$f->setText($this->isbn_created);
$val = ($f->getHeight() - $f->getUnderBaseline()) / $this->scale + $this->SIZE_SPACING_FONT;
$this->offsetY = $val;
} elseif($this->getISBNFont() !== 0) {
$val = (imagefontheight($this->getISBNFont()) + 2) / $this->scale;
$this->offsetY = $val;
}
}
}
function isCharsAllowed(&$im) {
$c = strlen($this->text);
// Special case, if we have 10 digits, the last one can be X
if($c === 10) {
if(array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') {
$this->drawError($im, 'Char \'' . $this->text[9] . '\' not allowed.');
return false;
}
// Drop the last char
$this->text = substr($this->text, 0, 9);
}
return BCGean13::isCharsAllowed($im);
}
function isLengthCorrect(&$im) {
$c = strlen($this->text);
// If we have 13 chars just flush the last one
if($c === 13) {
$this->text = substr($this->text, 0, 12);
return true;
} elseif($c === 12) {
return true;
} elseif($c === 9 || $c === 10) {
if($c === 10) {
// Before dropping it, we check if it's legal
if(array_search($this->text[9], $this->keys) === false && $this->text[9] !== 'X') {
return false;
}
$this->text = substr($this->text, 0, 9);
}
if($this->gs1 === $this->GS1_AUTO || $this->gs1 === $this->GS1_PREFIX978) {
$this->text = '978' . $this->text;
} elseif($this->gs1 === $this->GS1_PREFIX979) {
$this->text = '979' . $this->text;
}
// We changed the start, recalculate the offset label
BCGean13::setLabelOffset();
return true;
} else {
if($im !== null) {
$this->drawError($im, 'Must provide 9, 10, 12 or 13 digits.');
}
return false;
}
}
/**
* Overloaded method for drawing special label
*
* @param resource $im
*/
function drawText(&$im) {
BCGean13::drawText($im);
if(strlen($this->isbn_created) > 0) {
$pA = $this->getMaxSize();
$pB = BCGBarcode1D::getMaxSize();
$w = $pA[0] - $pB[0];
if(is_a($this->getISBNFont(), 'BCGFont')) {
$textfont = $this->getISBNFont(); // clone
$textfont->setText($this->isbn_created);
$xPosition = ($w / 2) - ($textfont->getWidth() / 2) + $this->offsetX * $this->scale;
$yPosition = $this->offsetY * $this->scale - $this->SIZE_SPACING_FONT;
$textfont->draw($im, $this->colorFg->allocate($im), $xPosition, $yPosition);
} elseif($this->getISBNFont() !== 0) {
$xPosition = ($w / 2) - (strlen($this->isbn_created) / 2) * imagefontwidth($this->getISBNFont()) + $this->offsetX * $this->scale;
$yPosition = $this->offsetY * $this->scale - $this->SIZE_SPACING_FONT - imagefontheight($this->getISBNFont());
imagestring($im, $this->getISBNFont(), $xPosition, $yPosition, $this->isbn_created, $this->colorFg->allocate($im));
}
}
}
function &getISBNFont() {
if($this->isbn_textfont === null) {
return $this->textfont;
} else {
return $this->isbn_textfont;
}
}
function createISBNText() {
if($this->isbn_text === $this->AUTO_LABEL && !empty($this->text)) {
// We try to create the ISBN Text... the hyphen really depends the ISBN agency.
// We just put one before the checksum and one after the GS1 if present.
$c = strlen($this->text);
if($c === 12 || $c === 13) {
// If we have 13 characters now, just transform it temporarily to find the checksum...
// Further in the code we take care of that anyway.
$lastCharacter = '';
if($c === 13) {
$lastCharacter = $this->text[12];
$this->text = substr($this->text, 0, 12);
}
$checksum = $this->processChecksum();
$this->isbn_created = 'ISBN ' . substr($this->text, 0, 3) . '-' . substr($this->text, 3, 9) . '-' . $checksum;
// Put the last character back
if($c === 13) {
$this->text .= $lastCharacter;
}
} elseif($c === 9 || $c === 10) {
$checksum = 0;
for($i = 10; $i >= 2; $i--) {
$checksum += $this->text[10 - $i] * $i;
}
$checksum = 11 - $checksum % 11;
if($checksum === 10) {
$checksum = 'X';
}
$this->isbn_created = 'ISBN ' . substr($this->text, 0, 9) . '-' . $checksum;
} else {
$this->isbn_created = '';
}
} else {
$this->isbn_created = $this->isbn_text;
}
}
};
?>

View File

@@ -0,0 +1,170 @@
<?php
/**
* BCGmsi.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - MSI Plessey
*
*--------------------------------------------------------------------
* Revision History
* v2.0.1 8 mar 2009 Jean-Sébastien Goupil Fix checksum 1 or 2
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.2 23 jul 2005 Jean-Sébastien Goupil Enhance rapidity
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGmsi.barcode.php,v 1.9 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.10
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGmsi extends BCGBarcode1D {
var $checksum;
/**
* Constructor
*/
function BCGmsi() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
$this->code = array(
'01010101', /* 0 */
'01010110', /* 1 */
'01011001', /* 2 */
'01011010', /* 3 */
'01100101', /* 4 */
'01100110', /* 5 */
'01101001', /* 6 */
'01101010', /* 7 */
'10010101', /* 8 */
'10010110' /* 9 */
);
$this->setChecksum(0);
}
function setChecksum($checksum) {
$checksum = intval($checksum);
if($checksum < 0 && $checksum > 2) {
$checksum = 0;
}
$this->checksum = $checksum;
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Checksum
$this->calculateChecksum();
// Starting Code
$this->drawChar($im, '10', true);
// Chars
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->text[$i]), true);
}
$c = count($this->checksumValue);
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->checksumValue[$i]), true);
}
// Ending Code
$this->drawChar($im, '010', true);
$this->drawText($im);
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$textlength = 12 * strlen($this->text) * $this->scale;
$startlength = 3 * $this->scale;
$checksumlength = $this->checksum * 12 * $this->scale;
$endlength = 4 * $this->scale;
return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Forming a new number
// If the original number is even, we take all even position
// If the original number is odd, we take all odd position
// 123456 = 246
// 12345 = 135
// Multiply by 2
// Add up all the digit in the result (270 : 2+7+0)
// Add up other digit not used.
// 10 - (? Modulo 10). If result = 10, change to 0
$last_text = $this->text;
$this->checksumValue = array();
for($i = 0; $i < $this->checksum; $i++) {
$new_text = '';
$new_number = 0;
$c = strlen($last_text);
if($c % 2 === 0) { // Even
$starting = 1;
} else {
$starting = 0;
}
for($j = $starting; $j < $c; $j += 2) {
$new_text .= $last_text[$j];
}
$new_text = strval(intval($new_text) * 2);
$c2 = strlen($new_text);
for($j = 0; $j < $c2; $j++) {
$new_number += intval($new_text[$j]);
}
for($j = ($starting === 0) ? 1 : 0; $j < $c; $j += 2) {
$new_number += intval($last_text[$j]);
}
$new_number = (10 - $new_number % 10) % 10;
$this->checksumValue[] = $new_number;
$last_text .= $new_number;
}
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
$ret = '';
$c = count($this->checksumValue);
for($i = 0; $i < $c; $i++) {
$ret .= $this->keys[$this->checksumValue[$i]];
}
return $ret;
}
return false;
}
};
?>

View File

@@ -0,0 +1,107 @@
<?php
/**
* BCGothercode.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - othercode
*
* Other Codes
* Starting with a bar and altern to space, bar, ...
* 0 is the smallest
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3b 2 jan 2006 Jean-Sébastien Goupil Correct error if $textfont was empty
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGothercode.barcode.php,v 1.9 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.10
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
// Function str_split is not available for PHP4. So we emulate it here.
if (!function_exists('str_split')) {
function str_split($string, $split_length = 1) {
$array = explode("\r\n", chunk_split($string, $split_length));
array_pop($array);
return $array;
}
}
class BCGothercode extends BCGBarcode1D {
/**
* Constructor
*/
function BCGothercode() {
BCGBarcode1D::BCGBarcode1D();
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$this->drawChar($im, $this->text, true);
$this->drawText($im);
}
function getLabel() {
$label = $this->label;
if($this->label === $this->AUTO_LABEL) {
$label = '';
}
return $label;
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$array = str_split($this->text, 1);
$textlength = (array_sum($array) + count($array)) * $this->scale;
return array($p[0] + $textlength, $p[1]);
}
/**
* Overloaded method for drawing special label
*
* @param resource $im
*/
function drawText(&$im) {
if($this->label !== $this->AUTO_LABEL && $this->label !== '') {
$pA = $this->getMaxSize();
$pB = BCGBarcode1D::getMaxSize();
$w = $pA[0] - $pB[0];
if(is_a($this->textfont, 'BCGFont')) {
$textfont = $this->textfont; // clone
$textfont->setText($this->label);
$xPosition = ($w / 2) - $textfont->getWidth() / 2 + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $textfont->getHeight() - $textfont->getUnderBaseline() + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale;
$text_color = $this->colorFg->allocate($im);
$textfont->draw($im, $text_color, $xPosition, $yPosition);
} elseif($this->textfont !== 0) {
$xPosition = ($w / 2) - (strlen($this->label) * imagefontwidth($this->textfont)) / 2 + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $this->offsetY * $this->scale + $this->SIZE_SPACING_FONT;
$text_color = $this->colorFg->allocate($im);
imagestring($im, $this->textfont, $xPosition, $yPosition, $this->label, $text_color);
}
}
}
};
?>

View File

@@ -0,0 +1,135 @@
<?php
/**
* BCGpostnet.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - PostNet
*
* ################ NOT TESTED ################
*
*--------------------------------------------------------------------
* Revision History
* v2.0.1 8 mar 2009 Jean-Sébastien Goupil Fix padding for the barcode
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil PHP5.1 compatible
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added + Redesign output
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGpostnet.barcode.php,v 1.12 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.13
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGpostnet extends BCGBarcode1D {
/**
* Constructor
*/
function BCGpostnet() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
$this->code = array(
'11000', /* 0 */
'00011', /* 1 */
'00101', /* 2 */
'00110', /* 3 */
'01001', /* 4 */
'01010', /* 5 */
'01100', /* 6 */
'10001', /* 7 */
'10010', /* 8 */
'10100' /* 9 */
);
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Must contain 5, 9 or 11 chars
if($c !== 5 && $c !== 9 && $c !== 11) {
$this->drawError($im, 'Must contain 5, 9 or 11 chars.');
$error_stop = true;
}
if($error_stop === false) {
// Checksum
$checksum = 0;
for($i = 0; $i < $c; $i++) {
$checksum += intval($this->text[$i]);
}
$checksum = 10 - ($checksum % 10);
// Starting Code
$this->drawChar($im, '1');
// Code
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($this->text[$i]));
}
// Checksum
$this->drawChar($im, $this->findCode($checksum));
//Ending Code
$this->drawChar($im, '1');
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$c = strlen($this->text);
$startlength = 6 * $this->scale;
$textlength = $c * 5 * 6 * $this->scale;
$checksumlength = 5 * 6 * $this->scale;
$endlength = 6 * $this->scale;
// We remove the white on the right
$removelength = - 3 * $this->scale;
return array($p[0] + $startlength + $textlength + $checksumlength + $endlength + $removelength, $p[1]);
}
/**
* Overloaded method for drawing special barcode
*
* @param resource $im
* @param string $code
* @param boolean $last
*/
function drawChar(&$im, $code, $last = false) {
$c = strlen($code);
for($i = 0; $i < $c; $i++) {
if($code[$i] === '0') {
$posY = $this->thickness / 2;
} else {
$posY = 0;
}
$this->drawFilledRectangle($im, $this->positionX, $posY, $this->positionX + 2, $this->thickness, $this->COLOR_FG);
$this->positionX += 2 * 3;
}
}
};
?>

View File

@@ -0,0 +1,161 @@
<?php
/**
* BCGs25.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - Standard 2 of 5
*
* NOTE: It is really tough to read this barcode !
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.2 23 jul 2005 Jean-Sébastien Goupil Correct Checksum
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGs25.barcode.php,v 1.8 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.10
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGs25 extends BCGBarcode1D {
var $checksum;
/**
* Constructor
*/
function BCGs25() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
$this->code = array(
'0000202000', /* 0 */
'2000000020', /* 1 */
'0020000020', /* 2 */
'2020000000', /* 3 */
'0000200020', /* 4 */
'2000200000', /* 5 */
'0020200000', /* 6 */
'0000002020', /* 7 */
'2000002000', /* 8 */
'0020002000' /* 9 */
);
$this->setChecksum(false);
}
function setChecksum($checksum) {
$this->checksum = (bool)$checksum;
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Must be even
if($c % 2 !== 0 && $this->checksum === false) {
$this->drawError($im, 's25 must be even if checksum is false.');
$error_stop = true;
} elseif($c % 2 === 0 && $this->checksum === true) {
$this->drawError($im, 's25 must be odd if checksum is true.');
$error_stop = true;
}
if($error_stop === false) {
$temp_text = $this->text;
// Checksum
if($this->checksum === true) {
$this->calculateChecksum();
$temp_text .= $this->keys[$this->checksumValue];
}
// Starting Code
$this->drawChar($im, '101000', true);
// Chars
$c = strlen($temp_text);
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Ending Code
$this->drawChar($im, '10001', true);
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$c = strlen($this->text);
$startlength = 8 * $this->scale;
$textlength = $c * 14 * $this->scale;
$checksumlength = 0;
if($c % 2 !== 0) {
$checksumlength = 14 * $this->scale;
}
$endlength = 7 * $this->scale;
return array($p[0] + $startlength + $textlength + $checksumlength + $endlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Calculating Checksum
// Consider the right-most digit of the message to be in an "even" position,
// and assign odd/even to each character moving from right to left
// Even Position = 3, Odd Position = 1
// Multiply it by the number
// Add all of that and do 10-(?mod10)
$even = true;
$this->checksumValue = 0;
$c = strlen($this->text);
for($i = $c; $i > 0; $i--) {
if($even === true) {
$multiplier = 3;
$even = false;
} else {
$multiplier = 1;
$even = true;
}
$this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier;
}
$this->checksumValue = (10 - $this->checksumValue % 10) % 10;
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
}
};
?>

View File

@@ -0,0 +1,362 @@
<?php
/**
* BCGupca.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - UPC-A
*
* UPC-A contains
* - 2 system digits (1 not provided, a 0 is added automatically)
* - 5 manufacturer code digits
* - 5 product digits
* - 1 checksum digit
*
* The checksum is always displayed.
*
*--------------------------------------------------------------------
* Revision History
* v2.0.1 8 mar 2009 Jean-Sébastien Goupil Fix padding for the barcode
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3 6 feb 2006 Jean-Sébastien Goupil Fix label position + Using correctly static method
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.2 23 jul 2005 Jean-Sébastien Goupil Enhance rapidity
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added + correcting output when text was present
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGupca.barcode.php,v 1.12 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.15
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGupca extends BCGBarcode1D {
var $codeParity = array();
/**
* Constructor
*/
function BCGupca() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
// Left-Hand Odd Parity starting with a space
// Left-Hand Even Parity is the inverse (0=0012) starting with a space
// Right-Hand is the same of Left-Hand starting with a bar
$this->code = array(
'2100', /* 0 */
'1110', /* 1 */
'1011', /* 2 */
'0300', /* 3 */
'0021', /* 4 */
'0120', /* 5 */
'0003', /* 6 */
'0201', /* 7 */
'0102', /* 8 */
'2001' /* 9 */
);
// Parity, 0=Odd, 1=Even for manufacturer code. Depending on 1st System Digit
$this->codeParity = array(
array(0,0,0,0,0), /* 0 */
array(0,1,0,1,1), /* 1 */
array(0,1,1,0,1), /* 2 */
array(0,1,1,1,0), /* 3 */
array(1,0,0,1,1), /* 4 */
array(1,1,0,0,1), /* 5 */
array(1,1,1,0,0), /* 6 */
array(1,0,1,0,1), /* 7 */
array(1,0,1,1,0), /* 8 */
array(1,1,0,1,0) /* 9 */
);
}
function parse($text) {
BCGBarcode1D::parse($text);
$this->setLabelOffset();
}
function setFont($font) {
BCGBarcode1D::setFont($font);
$this->setLabelOffset();
}
function setLabel($label) {
BCGBarcode1D::setLabel($label);
$this->setLabelOffset();
}
function setOffsetX($offsetX) {
BCGBarcode1D::setOffsetX($offsetX);
$this->setLabelOffset();
}
function setScale($scale) {
BCGBarcode1D::setScale($scale);
$this->setLabelOffset();
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Must contain 11 chars
if($c !== 11) {
$this->drawError($im, 'Must contain 11 chars, the 12th digit is automatically added.');
$error_stop = true;
}
if($error_stop === false) {
// The following code is exactly the same as EAN13. We just add a 0 in front of the code !
$this->text = '0'.$this->text; // We will remove it at the end... don't worry
// Checksum
$this->calculateChecksum();
$temp_text = $this->text . $this->keys[$this->checksumValue];
// Starting Code
$this->drawChar($im, '000', true);
// Draw Second Code
$this->drawChar($im, $this->findCode($temp_text[1]), false);
// Draw Manufacturer Code
for($i = 0; $i < 5; $i++) {
$this->drawChar($im, BCGupca::inverse($this->findCode($temp_text[$i + 2]), $this->codeParity[$temp_text[0]][$i]), false);
}
// Draw Center Guard Bar
$this->drawChar($im, '00000', false);
// Draw Product Code
for($i = 7; $i < 13; $i++) {
$this->drawChar($im, $this->findCode($temp_text[$i]), true);
}
// Draw Right Guard Bar
$this->drawChar($im, '000', true);
$this->drawText($im);
// We remove the 0 in front, as we said :)
$this->text = substr($this->text, 1);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$startlength = 3 * $this->scale;
$centerlength = 5 * $this->scale;
$textlength = 12 * 7 * $this->scale;
$endlength = 3 * $this->scale;
$lastcharlength = $this->getEndPosition() + 2;
return array($p[0] + $startlength + $centerlength + $textlength + $endlength + $lastcharlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Calculating Checksum
// Consider the right-most digit of the message to be in an "odd" position,
// and assign odd/even to each character moving from right to left
// Odd Position = 3, Even Position = 1
// Multiply it by the number
// Add all of that and do 10-(?mod10)
$odd = true;
$this->checksumValue = 0;
$c = strlen($this->text);
for($i = $c; $i > 0; $i--) {
if($odd === true) {
$multiplier = 3;
$odd = false;
} else {
$multiplier = 1;
$odd = true;
}
if(!isset($this->keys[$this->text[$i - 1]])) {
return;
}
$this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier;
}
$this->checksumValue = (10 - $this->checksumValue % 10) % 10;
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
}
/**
* Overloaded method for drawing special label
*
* @param resource $im
*/
function drawText(&$im) {
if($this->label !== $this->AUTO_LABEL) {
BCGBarcode1D::drawText($im);
} elseif($this->label !== '') {
$temp_text = $this->text . $this->keys[$this->checksumValue];
if(is_a($this->textfont, 'BCGFont')) {
$code1 = 0;
$code2 = 0;
$this->textfont->setText($temp_text);
$this->drawExtendedBars($im, $this->textfont->getHeight(), $code1, $code2);
// We need to separate the text, one on the left and one on the right, one starting and one ending
$text0 = substr($temp_text, 1, 1);
$text1 = substr($temp_text, 2, 5);
$text2 = substr($temp_text, 7, 5);
$text3 = substr($temp_text, 12, 1);
$font0 = $this->textfont; // clone
$font1 = $this->textfont; // clone
$font2 = $this->textfont; // clone
$font3 = $this->textfont; // clone
$font0->setText($text0);
$font1->setText($text1);
$font2->setText($text2);
$font3->setText($text3);
$xPosition0 = $this->offsetX * $this->scale - $font0->getWidth() - 4; // -4 is just for beauty;
$xPosition3 = $this->offsetX * $this->scale + $this->positionX * $this->scale + 2;
$yPosition0 = $this->thickness * $this->scale + $font0->getHeight() / 2 + $this->offsetY * $this->scale;
$xPosition1 = ($this->scale * 36 - $font1->getWidth()) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale;
$xPosition2 = ($this->scale * 37 - $font2->getWidth()) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $this->textfont->getHeight() + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale;
$text_color = $this->colorFg->allocate($im);
$font0->draw($im, $text_color, $xPosition0, $yPosition0);
$font1->draw($im, $text_color, $xPosition1, $yPosition);
$font2->draw($im, $text_color, $xPosition2, $yPosition);
$font3->draw($im, $text_color, $xPosition3, $yPosition0);
} elseif($this->textfont !== 0) {
$code1 = 0;
$code2 = 0;
$this->drawExtendedBars($im, 9, $code1, $code2);
$xPosition0 = $this->offsetX * $this->scale - imagefontwidth($this->textfont);
$xPosition3 = $this->offsetX * $this->scale + $this->positionX * $this->scale + 2;
$yPosition0 = $this->thickness * $this->scale - imagefontheight($this->textfont) / 2 + $this->offsetY * $this->scale;
$xPosition1 = ($this->scale * 36 - imagefontwidth($this->textfont) * 5) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale;
$xPosition2 = ($this->scale * 37 - imagefontwidth($this->textfont) * 5) / 2 + $code2 * $this->scale + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $this->offsetY * $this->scale;
$text_color = $this->colorFg->allocate($im);
imagechar($im, $this->textfont, $xPosition0, $yPosition0, $temp_text[1], $text_color);
imagestring($im, $this->textfont, $xPosition1, $yPosition, substr($temp_text, 2, 5), $text_color);
imagestring($im, $this->textfont, $xPosition2, $yPosition, substr($temp_text, 7, 5), $text_color);
imagechar($im, $this->textfont, $xPosition3, $yPosition0, $temp_text[12], $text_color);
}
}
}
function setLabelOffset() {
$label = $this->getLabel();
if(!empty($label)) {
if(is_a($this->textfont, 'BCGFont')) {
$f = $this->textfont; // clone
$f->setText(substr($label, 0, 1));
$val = ($f->getWidth() + 5) / $this->scale;
if($val > $this->offsetX) {
$this->offsetX = $val;
}
} elseif($this->textfont !== 0) {
$val = (imagefontwidth($this->textfont) + 2) / $this->scale;
if($val > $this->offsetX) {
$this->offsetX = $val;
}
}
}
}
function drawExtendedBars(&$im, $plus, &$code1, &$code2) {
$temp_text = $this->text . $this->keys[$this->checksumValue];
$rememberX = $this->positionX;
$rememberH = $this->thickness;
// We increase the bars
// First 2 Bars
$this->thickness = $this->thickness + ceil($plus / $this->scale);
$this->positionX = 0;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->drawSingleBar($im, $this->COLOR_FG);
// Attemping to increase the 2 following bars
$this->positionX += 1;
$code1 = $this->positionX;
$temp_value = $this->findCode($temp_text[1]);
$this->drawChar($im, $temp_value, false);
$code1 = $this->positionX;
// Center Guard Bar
$this->positionX += 36;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->drawSingleBar($im, $this->COLOR_FG);
$code2 = $this->positionX;
// Attemping to increase the 2 last bars
$this->positionX += 37;
$temp_value = $this->findCode($temp_text[12]);
$this->drawChar($im, $temp_value, true);
// Completly last bars
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX = $rememberX;
$this->thickness = $rememberH;
}
function getEndPosition() {
if($this->label === $this->AUTO_LABEL) {
$this->calculateChecksum();
if(is_a($this->textfont, 'BCGFont')) {
$f = $this->textfont; // clone
$f->setText($this->checksumValue);
return $f->getWidth();
} elseif($this->textfont !== 0) {
return imagefontwidth($this->textfont);
}
}
return 0;
}
function inverse($text, $inverse = 1) { // static
if($inverse === 1) {
$text = strrev($text);
}
return $text;
}
};
?>

View File

@@ -0,0 +1,395 @@
<?php
/**
* BCGupce.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - UPC-E
*
* You can provide a UPC-A code (without dash), the code will transform
* it into a UPC-E format if it's possible.
* UPC-E contains
* - 1 system digits (not displayed but coded with parity)
* - 6 digits
* - 1 checksum digit (not displayed but coded with parity)
*
* The text returned is the UPC-E without the checksum.
* The checksum is always displayed.
*
*--------------------------------------------------------------------
* Revision History
* v2.0.1 8 mar 2009 Jean-Sébastien Goupil Fix padding for the barcode
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3 6 feb 2006 Jean-Sébastien Goupil Fix label position + Using correctly static method
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.2 23 jul 2005 Jean-Sébastien Goupil Enhance rapidity
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGupce.barcode.php,v 1.12 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.16
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGupce extends BCGBarcode1D {
var $codeParity = array();
/**
* Constructor
*/
function BCGupce() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
// Odd Parity starting with a space
// Even Parity is the inverse (0=0012) starting with a space
$this->code = array(
'2100', /* 0 */
'1110', /* 1 */
'1011', /* 2 */
'0300', /* 3 */
'0021', /* 4 */
'0120', /* 5 */
'0003', /* 6 */
'0201', /* 7 */
'0102', /* 8 */
'2001' /* 9 */
);
// Parity, 0=Odd, 1=Even for manufacturer code. Depending on 1st System Digit and Checksum
$this->codeParity = array(
array(
array(1,1,1,0,0,0), /* 0,0 */
array(1,1,0,1,0,0), /* 0,1 */
array(1,1,0,0,1,0), /* 0,2 */
array(1,1,0,0,0,1), /* 0,3 */
array(1,0,1,1,0,0), /* 0,4 */
array(1,0,0,1,1,0), /* 0,5 */
array(1,0,0,0,1,1), /* 0,6 */
array(1,0,1,0,1,0), /* 0,7 */
array(1,0,1,0,0,1), /* 0,8 */
array(1,0,0,1,0,1) /* 0,9 */
),
array(
array(0,0,0,1,1,1), /* 0,0 */
array(0,0,1,0,1,1), /* 0,1 */
array(0,0,1,1,0,1), /* 0,2 */
array(0,0,1,1,1,0), /* 0,3 */
array(0,1,0,0,1,1), /* 0,4 */
array(0,1,1,0,0,1), /* 0,5 */
array(0,1,1,1,0,0), /* 0,6 */
array(0,1,0,1,0,1), /* 0,7 */
array(0,1,0,1,1,0), /* 0,8 */
array(0,1,1,0,1,0) /* 0,9 */
)
);
}
function parse($text) {
BCGBarcode1D::parse($text);
$this->setLabelOffset();
}
function setFont($font) {
BCGBarcode1D::setFont($font);
$this->setLabelOffset();
}
function setLabel($label) {
BCGBarcode1D::setLabel($label);
$this->setLabelOffset();
}
function setOffsetX($offsetX) {
BCGBarcode1D::setOffsetX($offsetX);
$this->setLabelOffset();
}
function setScale($scale) {
BCGBarcode1D::setScale($scale);
$this->setLabelOffset();
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Must contain 11 chars
// Must contain 8 chars (if starting with upce directly)
// First Chars must be 0 or 1
if($c !== 11 && $c !== 6) {
$this->drawError($im, 'Provide an UPC-A (11 chars) or');
$this->drawError($im, 'You can also provide UPC-E directly (6 chars).');
$error_stop = true;
} elseif($this->text[0] !== '0' && $this->text[0] !== '1' && $c !== 6) {
$this->drawError($im, 'Must start with 0 or 1.');
$error_stop = true;
}
if($error_stop === false) {
if($c !== 6) {
// Checking if UPC-A is convertible
$upce = '';
if(substr($this->text, 3, 3) === '000' || substr($this->text, 3, 3) === '100' || substr($this->text, 3, 3) === '200') { // manufacturer code ends with 100,200 or 300
if(substr($this->text, 6, 2) === '00') { // Product must start with 00
$upce = substr($this->text, 1, 2) . substr($this->text, 8, 3) . substr($this->text, 3, 1);
} else {
$error_stop = true;
}
} elseif(substr($this->text, 4, 2) === '00') { // manufacturer code ends with 00
if(substr($this->text, 6, 3) === '000') { // Product must start with 000
$upce = substr($this->text, 1, 3) . substr($this->text, 9, 2) . '3';
} else {
$error_stop = true;
}
} elseif(substr($this->text, 5, 1) === '0') { // manufacturer code ends with 0
if(substr($this->text, 6, 4) === '0000') { // Product must start with 0000
$upce = substr($this->text, 1, 4) . substr($this->text, 10, 1) . '4';
} else {
$error_stop = true;
}
} else { // No zero leading at manufacturer code
if(substr($this->text, 6, 4) === '0000' && intval(substr($this->text, 10, 1)) >= 5 && intval(substr($this->text, 10, 1)) <= 9) { // Product must start with 0000 and must end by 5,6,7,8 or 9
$upce = substr($this->text, 1, 5) . substr($this->text, 10, 1);
} else {
$error_stop = true;
}
}
} else {
$upce = $this->text;
}
if($error_stop === false) {
if($c === 6) {
// We convert UPC-E to UPC-A to find the checksum
if($this->text[5] === '0' || $this->text[5] === '1' || $this->text[5] === '2') {
$upca = substr($this->text, 0, 2) . $this->text[5] . '0000' . substr($this->text, 2, 3);
} elseif($this->text[5] === '3') {
$upca = substr($this->text, 0, 3) . '00000' . substr($this->text, 3, 2);
} elseif($this->text[5] === '4') {
$upca = substr($this->text, 0, 4) . '00000' . $this->text[4];
} else {
$upca = substr($this->text, 0, 5) . '0000' . $this->text[5];
}
$this->text = '0' . $upca;
}
$this->calculateChecksum();
// Starting Code
$this->drawChar($im, '000', true);
$c = strlen($upce);
for($i = 0; $i < $c; $i++) {
$this->drawChar($im, BCGupce::inverse($this->findCode($upce[$i]), $this->codeParity[$this->text[0]][$this->checksumValue][$i]), false);
}
// Draw Center Guard Bar
$this->drawChar($im, '00000', false);
// Draw Right Bar
$this->drawChar($im, '0', true);
$this->text = $this->text[0] . $upce;
$this->drawText($im);
} else {
$this->drawError($im, 'Your UPC-A can\'t be converted to UPC-E.');
}
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$startlength = 3 * $this->scale;
$centerlength = 5 * $this->scale;
$textlength = 6 * 7 * $this->scale;
$endlength = $this->scale;
$lastcharlength = $this->getEndPosition() + 2;
return array($p[0] + $startlength + $centerlength + $textlength + $endlength + $lastcharlength, $p[1]);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Calculating Checksum
// Consider the right-most digit of the message to be in an "odd" position,
// and assign odd/even to each character moving from right to left
// Odd Position = 3, Even Position = 1
// Multiply it by the number
// Add all of that and do 10-(?mod10)
$odd = true;
$this->checksumValue = 0;
$c = strlen($this->text);
for($i = $c; $i > 0; $i--) {
if($odd === true) {
$multiplier = 3;
$odd = false;
} else {
$multiplier = 1;
$odd = true;
}
if(!isset($this->keys[$this->text[$i - 1]])) {
return;
}
$this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier;
}
$this->checksumValue = (10 - $this->checksumValue % 10) % 10;
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
}
/**
* Overloaded method for drawing special label
*
* @param resource $im
*/
function drawText(&$im) {
if($this->label !== $this->AUTO_LABEL) {
BCGBarcode1D::drawText($im);
} elseif($this->label !== '') {
$temp_text = $this->text . $this->keys[$this->checksumValue];
if(is_a($this->textfont, 'BCGFont')) {
$thic->code1 = 0;
$this->textfont->setText($temp_text);
$this->drawExtendedBars($im, $this->textfont->getHeight(), $code1);
// We need to separate the text, one on the left and one on the right, one starting and one ending
$text0 = substr($temp_text, 0, 1);
$text1 = substr($temp_text, 1, 6);
$text2 = substr($temp_text, 7, 1);
$font0 = $this->textfont; // clone
$font1 = $this->textfont; // clone
$font2 = $this->textfont; // clone
$font0->setText($text0);
$font1->setText($text1);
$font2->setText($text2);
$xPosition0 = $this->offsetX * $this->scale - $font0->getWidth() - 4; // -4 is just for beauty;
$xPosition2 = $this->offsetX * $this->scale + $this->positionX * $this->scale + 2;
$yPosition0 = $this->thickness * $this->scale + $font0->getHeight() / 2 + $this->offsetY * $this->scale;
$xPosition1 = ($this->scale * 46 - $font1->getWidth()) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $this->textfont->getHeight() + $this->SIZE_SPACING_FONT + $this->offsetY * $this->scale;
$text_color = $this->colorFg->allocate($im);
$font0->draw($im, $text_color, $xPosition0, $yPosition0);
$font1->draw($im, $text_color, $xPosition1, $yPosition);
$font2->draw($im, $text_color, $xPosition2, $yPosition0);
} elseif($this->textfont !== 0) {
$thic->code1 = 0;
$this->drawExtendedBars($im, 9, $code1);
$xPosition0 = $this->offsetX * $this->scale - imagefontwidth($this->textfont);
$xPosition2 = $this->offsetX * $this->scale + $this->positionX * $this->scale + 2;
$yPosition0 = $this->thickness * $this->scale - imagefontheight($this->textfont) / 2 + $this->offsetY * $this->scale;
$xPosition1 = ($this->scale * 46 - imagefontwidth($this->textfont) * 6) / 2 + $code1 * $this->scale + $this->offsetX * $this->scale;
$yPosition = $this->thickness * $this->scale + $this->offsetY * $this->scale;
$text_color = $this->colorFg->allocate($im);
imagechar($im, $this->textfont, $xPosition0, $yPosition0, $temp_text[0], $text_color);
imagestring($im, $this->textfont, $xPosition1, $yPosition, substr($temp_text, 1, 6), $text_color);
imagechar($im, $this->textfont, $xPosition2, $yPosition0, $temp_text[7], $text_color);
}
}
}
function drawExtendedBars(&$im, $plus, &$code1) {
$rememberX = $this->positionX;
$rememberH = $this->thickness;
// We increase the bars
$this->thickness = $this->thickness + ceil($plus / $this->scale);
$this->positionX = 0;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->drawSingleBar($im, $this->COLOR_FG);
$code1 = $this->positionX;
// Last Bars
$this->positionX += 46;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX += 2;
$this->drawSingleBar($im, $this->COLOR_FG);
$this->positionX = $rememberX;
$this->thickness = $rememberH;
}
function getEndPosition() {
if($this->label === $this->AUTO_LABEL) {
$this->calculateChecksum();
if(is_a($this->textfont, 'BCGFont')) {
$f = $this->textfont; // clone
$f->setText($this->checksumValue);
return $f->getWidth();
} elseif($this->textfont !== 0) {
return imagefontwidth($this->textfont);
}
}
return 0;
}
function setLabelOffset() {
$label = $this->getLabel();
if(!empty($label)) {
if(is_a($this->textfont, 'BCGFont')) {
$f = $this->textfont; // clone
$f->setText(substr($label, 0, 1));
$val = ($f->getWidth() + 5) / $this->scale;
if($val > $this->offsetX) {
$this->offsetX = $val;
}
} elseif($this->textfont !== 0) {
$val = (imagefontwidth($this->textfont) + 2) / $this->scale;
if($val > $this->offsetX) {
$this->offsetX = $val;
}
}
}
}
function inverse($text, $inverse = 1) { // static
if($inverse === 1) {
$text = strrev($text);
}
return $text;
}
};
?>

View File

@@ -0,0 +1,207 @@
<?php
/**
* BCGupcext2.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - UPC Supplemental Barcode 2 digits
*
* Working with UPC-A, UPC-E, EAN-13, EAN-8
* This includes 2 digits (normaly for publications)
* Must be placed next to UPC or EAN Code
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3 6 feb 2006 Jean-Sébastien Goupil Using correctly static method
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil PHP5.1 compatible
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added + correcting output error
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGupcext2.barcode.php,v 1.10 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.13
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGupcext2 extends BCGBarcode1D {
var $codeParity = array();
/**
* Constructor
*/
function BCGupcext2() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
$this->code = array(
'2100', /* 0 */
'1110', /* 1 */
'1011', /* 2 */
'0300', /* 3 */
'0021', /* 4 */
'0120', /* 5 */
'0003', /* 6 */
'0201', /* 7 */
'0102', /* 8 */
'2001' /* 9 */
);
// Parity, 0=Odd, 1=Even. Depending on ?%4
$this->codeParity = array(
array(0,0), /* 0 */
array(0,1), /* 1 */
array(1,0), /* 2 */
array(1,1) /* 3 */
);
}
function parse($text) {
BCGBarcode1D::parse($text);
$this->setLabelOffset();
}
function setFont($font) {
BCGBarcode1D::setFont($font);
$this->setLabelOffset();
}
function setLabel($label) {
BCGBarcode1D::setLabel($label);
$this->setLabelOffset();
}
function setOffsetY($offsetY) {
BCGBarcode1D::setOffsetY($offsetY);
$this->setLabelOffset();
}
function setScale($scale) {
BCGBarcode1D::setScale($scale);
$this->setLabelOffset();
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Must contain 2 chars
if($c !== 2) {
$this->drawError($im, 'Must contain 2 chars.');
$error_stop = true;
}
if($error_stop === false) {
// Starting Code
$this->drawChar($im, '001', true);
// Code
for($i = 0; $i < 2; $i++) {
$this->drawChar($im, BCGupcext2::inverse($this->findCode($this->text[$i]), $this->codeParity[intval($this->text) % 4][$i]), false);
if($i === 0) {
$this->DrawChar($im, '00', false); // Inter-char
}
}
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$startlength = 4 * $this->scale;
$textlength = 2 * 7 * $this->scale;
$intercharlength = 2 * $this->scale;
$label = $this->getLabel();
$textHeight = 0;
if(!empty($label)) {
if(is_a($this->textfont, 'BCGFont')) {
$textfont = $this->textfont; // clone
$textfont->setText($label);
$textHeight = $textfont->getHeight() + $this->SIZE_SPACING_FONT;
} elseif($this->textfont !== 0) {
$textHeight = imagefontheight($this->textfont) + $this->SIZE_SPACING_FONT;
}
}
return array($p[0] + $startlength + $textlength + $intercharlength, $p[1] - $textHeight);
}
/**
* Overloaded method for drawing special label
*
* @param resource $im
*/
function drawText(&$im) {
$label = $this->getLabel();
if(!empty($label)) {
$pA = $this->getMaxSize();
$pB = BCGBarcode1D::getMaxSize();
$w = $pA[0] - $pB[0];
if(is_a($this->textfont, 'BCGFont')) {
$textfont = $this->textfont; // clone
$textfont->setText($label);
$xPosition = ($w / 2) - ($textfont->getWidth() / 2) + $this->offsetX * $this->scale;
$yPosition = $this->offsetY * $this->scale - $this->SIZE_SPACING_FONT;
$textfont->draw($im, $this->colorFg->allocate($im), $xPosition, $yPosition);
} elseif($this->textfont !== 0) {
$xPosition = ($w / 2) - (strlen($label) / 2) * imagefontwidth($this->textfont) + $this->offsetX * $this->scale;
$yPosition = $this->offsetY * $this->scale - $this->SIZE_SPACING_FONT - imagefontheight($this->textfont);
imagestring($im, $this->textfont, $xPosition, $yPosition, $label, $this->colorFg->allocate($im));
}
}
}
function setLabelOffset() {
$label = $this->getLabel();
if(!empty($label)) {
if(is_a($this->textfont, 'BCGFont')) {
$f = $this->textfont; // clone
$f->setText($label);
$val = ($f->getHeight() - $f->getUnderBaseline()) / $this->scale + $this->SIZE_SPACING_FONT;
if($val > $this->offsetY) {
$this->offsetY = $val;
}
} elseif($this->textfont !== 0) {
$val = (imagefontheight($this->textfont) + 2) / $this->scale;
if($val > $this->offsetY) {
$this->offsetY = $val;
}
}
}
}
function inverse($text, $inverse = 1) { // static
if($inverse === 1) {
$text = strrev($text);
}
return $text;
}
};
?>

View File

@@ -0,0 +1,263 @@
<?php
/**
* BCGupcext5.barcode.php
*--------------------------------------------------------------------
*
* Sub-Class - UPC Supplemental Barcode 2 digits
*
* Working with UPC-A, UPC-E, EAN-13, EAN-8
* This includes 5 digits (normaly for suggested retail price)
* Must be placed next to UPC or EAN Code
* If 90000 -> No suggested Retail Price
* If 99991 -> Book Complimentary (normally free)
* If 90001 to 98999 -> Internal Purpose of Publisher
* If 99990 -> Used by the National Association of College Stores to mark used books
* If 0xxxx -> Price Expressed in British Pounds (xx.xx)
* If 5xxxx -> Price Expressed in U.S. dollars (US$xx.xx)
*
*--------------------------------------------------------------------
* Revision History
* v2.0.0 23 apr 2008 Jean-Sébastien Goupil New Version Update
* v1.2.3 6 feb 2006 Jean-Sébastien Goupil Using correctly static method
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil Checksum separated + PHP5.1 compatible
* v1.2.1 27 jun 2005 Jean-Sébastien Goupil Font support added
* V1.00 17 jun 2004 Jean-Sebastien Goupil
*--------------------------------------------------------------------
* $Id: BCGupcext5.barcode.php,v 1.10 2009/11/09 04:13:35 jsgoupil Exp $
* PHP5-Revision: 1.13
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGBarcode1D.php');
class BCGupcext5 extends BCGBarcode1D {
var $codeParity = array();
/**
* Constructor
*/
function BCGupcext5() {
BCGBarcode1D::BCGBarcode1D();
$this->keys = array('0','1','2','3','4','5','6','7','8','9');
$this->code = array(
'2100', /* 0 */
'1110', /* 1 */
'1011', /* 2 */
'0300', /* 3 */
'0021', /* 4 */
'0120', /* 5 */
'0003', /* 6 */
'0201', /* 7 */
'0102', /* 8 */
'2001' /* 9 */
);
// Parity, 0=Odd, 1=Even. Depending Checksum
$this->codeParity = array(
array(1,1,0,0,0), /* 0 */
array(1,0,1,0,0), /* 1 */
array(1,0,0,1,0), /* 2 */
array(1,0,0,0,1), /* 3 */
array(0,1,1,0,0), /* 4 */
array(0,0,1,1,0), /* 5 */
array(0,0,0,1,1), /* 6 */
array(0,1,0,1,0), /* 7 */
array(0,1,0,0,1), /* 8 */
array(0,0,1,0,1) /* 9 */
);
}
function parse($text) {
BCGBarcode1D::parse($text);
$this->setLabelOffset();
}
function setFont($font) {
BCGBarcode1D::setFont($font);
$this->setLabelOffset();
}
function setLabel($label) {
BCGBarcode1D::setLabel($label);
$this->setLabelOffset();
}
function setOffsetY($offsetY) {
BCGBarcode1D::setOffsetY($offsetY);
$this->setLabelOffset();
}
function setScale($scale) {
BCGBarcode1D::setScale($scale);
$this->setLabelOffset();
}
/**
* Draws the barcode
*
* @param resource $im
*/
function draw(&$im) {
$error_stop = false;
// Checking if all chars are allowed
$c = strlen($this->text);
for($i = 0; $i < $c; $i++) {
if(array_search($this->text[$i], $this->keys) === false) {
$this->drawError($im, 'Char \'' . $this->text[$i] . '\' not allowed.');
$error_stop = true;
}
}
if($error_stop === false) {
// Must contain 5 chars
if($c !== 5) {
$this->drawError($im, 'Must contain 5 chars.');
$error_stop = true;
}
if($error_stop === false) {
// Checksum
$this->calculateChecksum();
// Starting Code
$this->drawChar($im, '001', true);
// Code
for($i = 0; $i < 5; $i++) {
$this->drawChar($im, BCGupcext5::inverse($this->findCode($this->text[$i]), $this->codeParity[$this->checksumValue][$i]), false);
if($i < 4) {
$this->drawChar($im, '00', false); // Inter-char
}
}
$this->drawText($im);
}
}
}
/**
* Returns the maximal size of a barcode
*
* @return int[]
*/
function getMaxSize() {
$p = BCGBarcode1D::getMaxSize();
$startlength = 4 * $this->scale;
$textlength = 5 * 7 * $this->scale;
$intercharlength = 2 * 4 * $this->scale;
$label = $this->getLabel();
$textHeight = 0;
if(!empty($label)) {
if(is_a($this->textfont, 'BCGFont')) {
$textfont = $this->textfont; // clone
$textfont->setText($label);
$textHeight = $textfont->getHeight() + $this->SIZE_SPACING_FONT;
} elseif($this->textfont !== 0) {
$textHeight = imagefontheight($this->textfont) + $this->SIZE_SPACING_FONT;
}
}
return array($p[0] + $startlength + $textlength + $intercharlength, $p[1] - $textHeight);
}
/**
* Overloaded method to calculate checksum
*/
function calculateChecksum() {
// Calculating Checksum
// Consider the right-most digit of the message to be in an "odd" position,
// and assign odd/even to each character moving from right to left
// Odd Position = 3, Even Position = 9
// Multiply it by the number
// Add all of that and do ?mod10
$odd = true;
$this->checksumValue = 0;
$c = strlen($this->text);
for($i = $c; $i > 0; $i--) {
if($odd === true) {
$multiplier = 3;
$odd = false;
} else {
$multiplier = 9;
$odd = true;
}
if(!isset($this->keys[$this->text[$i - 1]])) {
return;
}
$this->checksumValue += $this->keys[$this->text[$i - 1]] * $multiplier;
}
$this->checksumValue = $this->checksumValue % 10;
}
/**
* Overloaded method to display the checksum
*/
function processChecksum() {
if($this->checksumValue === false) { // Calculate the checksum only once
$this->calculateChecksum();
}
if($this->checksumValue !== false) {
return $this->keys[$this->checksumValue];
}
return false;
}
/**
* Overloaded method for drawing special label
*
* @param resource $im
*/
function drawText(&$im) {
$label = $this->getLabel();
if(!empty($label)) {
$pA = $this->getMaxSize();
$pB = BCGBarcode1D::getMaxSize();
$w = $pA[0] - $pB[0];
if(is_a($this->textfont, 'BCGFont')) {
$textfont = $this->textfont; // clone
$textfont->setText($label);
$xPosition = ($w / 2) - ($textfont->getWidth() / 2) + $this->offsetX * $this->scale;
$yPosition = $this->offsetY * $this->scale - $this->SIZE_SPACING_FONT;
$textfont->draw($im, $this->colorFg->allocate($im), $xPosition, $yPosition);
} elseif($this->textfont !== 0) {
$xPosition = ($w / 2) - (strlen($label) / 2) * imagefontwidth($this->textfont) + $this->offsetX * $this->scale;
$yPosition = $this->offsetY * $this->scale - $this->SIZE_SPACING_FONT - imagefontheight($this->textfont);
imagestring($im, $this->textfont, $xPosition, $yPosition, $label, $this->colorFg->allocate($im));
}
}
}
function setLabelOffset() {
$label = $this->getLabel();
if(!empty($label)) {
if(is_a($this->textfont, 'BCGFont')) {
$f = $this->textfont; // clone
$f->setText($label);
$val = ($f->getHeight() - $f->getUnderBaseline()) / $this->scale + $this->SIZE_SPACING_FONT;
if($val > $this->offsetY) {
$this->offsetY = $val;
}
} elseif($this->textfont !== 0) {
$val = (imagefontheight($this->textfont) + 2) / $this->scale;
if($val > $this->offsetY) {
$this->offsetY = $val;
}
}
}
}
function inverse($text, $inverse = 1) { // static
if($inverse === 1) {
$text = strrev($text);
}
return $text;
}
};
?>

View File

@@ -0,0 +1,48 @@
<?php
/**
* JoinDraw.php
*--------------------------------------------------------------------
*
* Enable to join 2 BCGDrawing or 2 image object to make only one image.
* There are some options for alignement.
*
* ! THIS CLASS IS NOT AVAILABLE FOR PHP4 !
*
*--------------------------------------------------------------------
* Revision History
* v2.0.1 09 mar 2009 Jean-Sébastien Goupil Update for BCG classes
* v1.2.3b 31 dec 2005 Jean-Sébastien Goupil
*--------------------------------------------------------------------
* $Id: JoinDraw.php,v 1.4 2009/03/08 23:12:27 jsgoupil Exp $
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
class JoinDraw {
/**
* Construct the JoinDrawing Object.
* - $image1 and $image2 have to be BCGDrawing object or image object.
* - $space is the space between the two graphics in pixel.
* - $position is the position of the $image2 depending the $image1.
* - $alignment is the alignment of the $image2 if this one is smaller than $image1;
* if $image2 is bigger than $image1, the $image1 will be positionned on the opposite side specified.
*
* @param mixed $image1
* @param mixed $image2
* @param BCGColor $background
* @param int space
* @param int $position
* @param int $alignment
*/
function JoinDraw(&$image1, &$image2, $background, $space = 10, $position = 0, $alignment = 0) {
}
/**
* Returns the new $im created.
*
* @return resource
*/
function get_im() {
return false;
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* BCGDraw.php
*--------------------------------------------------------------------
*
* Base class to draw images
*
*--------------------------------------------------------------------
* Revision History
* v2.1.0 8 nov 2009 Jean-Sébastien Goupil
*--------------------------------------------------------------------
* $Id: BCGDraw.php,v 1.1 2009/11/09 04:15:10 jsgoupil Exp $
* PHP5-Revision: 1.1
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
class BCGDraw { // abstract
var $im;
var $filename;
/**
* Constructor
*
* @param resource $im
*/
function BCGDraw(&$im) {
$this->im = $im;
}
/**
* Sets the filename
*
* @param string $filename
*/
function setFilename($filename) {
$this->filename = $filename;
}
/**
* Method needed to draw the image based on its specification (JPG, GIF, etc.)
*/
function draw() {} // abstract public
}
?>

View File

@@ -0,0 +1,109 @@
<?php
/**
* BCGDrawJPG.php
*--------------------------------------------------------------------
*
* Image Class to draw JPG images with possibility to set DPI
*
*--------------------------------------------------------------------
* Revision History
* v2.1.0 8 nov 2009 Jean-Sébastien Goupil
*--------------------------------------------------------------------
* $Id: BCGDrawJPG.php,v 1.1 2009/11/09 04:15:10 jsgoupil Exp $
* PHP5-Revision: 1.1
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGDraw.php');
if (!function_exists('file_put_contents')) {
function file_put_contents($filename, $data) {
$f = @fopen($filename, 'w');
if (!$f) {
return false;
} else {
$bytes = fwrite($f, $data);
fclose($f);
return $bytes;
}
}
}
class BCGDrawJPG extends BCGDraw {
var $dpi;
var $quality;
/**
* Constructor
*
* @param resource $im
*/
function BCGDrawJPG(&$im) {
BCGDraw::BCGDraw($im);
}
/**
* Sets the DPI
*
* @param int $dpi
*/
function setDPI($dpi) {
if(is_int($dpi)) {
$this->dpi = max(1, $dpi);
} else {
$this->dpi = null;
}
}
/**
* Sets the quality of the JPG
*
* @param int $quality
*/
function setQuality($quality) {
$this->quality = $quality;
}
/**
* Draws the JPG on the screen or in a file
*/
function draw() {
ob_start();
imagejpeg($this->im, null, $this->quality);
$bin = ob_get_contents();
ob_end_clean();
$this->setInternalProperties($bin);
if (empty($this->filename)) {
echo $bin;
} else {
file_put_contents($this->filename, $bin);
}
}
function setInternalProperties(&$bin) { // private
$this->internalSetDPI($bin);
$this->internalSetC($bin);
}
function internalSetDPI(&$bin) { // private
if($this->dpi !== null) {
$bin = substr_replace($bin, pack("Cnn", 0x01, $this->dpi, $this->dpi), 13, 5);
}
}
function internalSetC(&$bin) { // private
if(strcmp(substr($bin, 0, 4), pack('H*', 'FFD8FFE0')) === 0) {
$offset = 4 + (ord($bin[4]) << 8 | ord($bin[5]));
$firstPart = substr($bin, 0, $offset);
$secondPart = substr($bin, $offset);
$cr = pack('H*', 'FFFE004447656E657261746564207769746820426172636F64652047656E657261746F7220666F722050485020687474703A2F2F7777772E626172636F64657068702E636F6D');
$bin = $firstPart;
$bin .= $cr;
$bin .= $secondPart;
}
}
}
?>

View File

@@ -0,0 +1,209 @@
<?php
/**
* BCGDrawPNG.php
*--------------------------------------------------------------------
*
* Image Class to draw PNG images with possibility to set DPI
*
*--------------------------------------------------------------------
* Revision History
* v2.1.0 8 nov 2009 Jean-Sébastien Goupil
*--------------------------------------------------------------------
* $Id: BCGDrawPNG.php,v 1.1 2009/11/09 04:15:10 jsgoupil Exp $
* PHP5-Revision: 1.1
*--------------------------------------------------------------------
* Copyright (C) Jean-Sebastien Goupil
* http://www.barcodephp.com
*/
include_once('BCGDraw.php');
if (!function_exists('file_put_contents')) {
function file_put_contents($filename, $data) {
$f = @fopen($filename, 'w');
if (!$f) {
return false;
} else {
$bytes = fwrite($f, $data);
fclose($f);
return $bytes;
}
}
}
class BCGDrawPNG extends BCGDraw {
var $dpi;
/**
* Constructor
*
* @param resource $im
*/
function BCGDrawPNG(&$im) {
BCGDraw::BCGDraw($im);
}
/**
* Sets the DPI
*
* @param int $dpi
*/
function setDPI($dpi) {
if(is_numeric($dpi)) {
$this->dpi = max(1, $dpi);
} else {
$this->dpi = null;
}
}
/**
* Draws the PNG on the screen or in a file
*/
function draw() {
ob_start();
imagepng($this->im);
$bin = ob_get_contents();
ob_end_clean();
$this->setInternalProperties($bin);
if (empty($this->filename)) {
echo $bin;
} else {
file_put_contents($this->filename, $bin);
}
}
function setInternalProperties(&$bin) { // private
// Scan all the ChunkType
if(strcmp(substr($bin, 0, 8), pack('H*', '89504E470D0A1A0A')) === 0) {
$chunks = $this->detectChunks($bin);
$this->internalSetDPI($bin, $chunks);
$this->internalSetC($bin, $chunks);
}
}
function detectChunks($bin) { // private
$data = substr($bin, 8);
$chunks = array();
$c = strlen($data);
$offset = 0;
while($offset < $c) {
$packed = unpack('Nsize/a4chunk', $data);
$size = $packed['size'];
$chunk = $packed['chunk'];
$chunks[] = array('offset'=>$offset + 8, 'size'=>$size, 'chunk'=>$chunk);
$jump = $size + 12;
$offset += $jump;
$data = substr($data, $jump);
}
return $chunks;
}
function internalSetDPI(&$bin, &$chunks) { // private
if($this->dpi !== null) {
$meters = (int)($this->dpi * 39.37007874);
$found = -1;
$c = count($chunks);
for($i = 0; $i < $c; $i++) {
// We already have a pHYs
if($chunks[$i]['chunk'] === 'pHYs') {
$found = $i;
break;
}
}
$data = 'pHYs' . pack('NNC', $meters, $meters, 0x01);
$crc = BCGDrawPNG::crc($data, 13);
$cr = pack('Na13N', 9, $data, $crc);
// We didn't have a pHYs
if($found == -1) {
// Don't do anything if we have a bad PNG
if($c >= 2 && $chunk[0]['chunk'] = 'IHDR') {
array_splice($chunks, 1, 0, array(array('offset'=>33, 'size'=>9, 'chunk'=>'pHYs')));
// Push the data
for($i = 2; $i < $c; $i++) {
$chunks[$i]['offset'] += 21;
}
$firstPart = substr($bin, 0, 33);
$secondPart = substr($bin, 33);
$bin = $firstPart;
$bin .= $cr;
$bin .= $secondPart;
}
} else {
$bin = substr_replace($bin, $cr, $chunks[$i]['offset'], 21);
}
}
}
function internalSetC(&$bin, &$chunks) { // private
if(count($chunks) >= 2 && $chunk[0]['chunk'] = 'IHDR') {
$firstPart = substr($bin, 0, 33);
$secondPart = substr($bin, 33);
$cr = pack('H*', '0000004C74455874436F707972696768740047656E657261746564207769746820426172636F64652047656E657261746F7220666F722050485020687474703A2F2F7777772E626172636F64657068702E636F6D597F70B8');
$bin = $firstPart;
$bin .= $cr;
$bin .= $secondPart;
}
// Chunks is dirty!! But we are done.
}
var $crc_table = array();
var $crc_table_computed = false;
function make_crc_table() { // private static
for($n = 0; $n < 256; $n++) {
$c = $n;
for ($k = 0; $k < 8; $k++) {
if (($c & 1) == 1) {
$c = 0xedb88320 ^ (BCGDrawPNG::SHR($c, 1));
} else {
$c = BCGDrawPNG::SHR($c, 1);
}
}
$this->crc_table[$n] = $c;
}
$this->crc_table_computed = true;
}
function SHR($x, $n) { // private static
$mask = 0x40000000;
if ($x < 0) {
$x &= 0x7FFFFFFF;
$mask = $mask >> ($n - 1);
return ($x >> $n) | $mask;
}
return (int)$x >> (int)$n;
}
function update_crc($crc, $buf, $len) { // private static
$c = $crc;
if (!$this->crc_table_computed) {
BCGDrawPNG::make_crc_table();
}
for($n = 0; $n < $len; $n++) {
$c = $this->crc_table[($c ^ ord($buf[$n])) & 0xff] ^ (BCGDrawPNG::SHR($c, 8));
}
return $c;
}
function crc($data, $len) { // private static
return BCGDrawPNG::update_crc(-1, $data, $len) ^ -1;
}
}
?>

Binary file not shown.

View File

@@ -0,0 +1,43 @@
<?php
// Including all required classes
require('class/BCGFont.php');
require('class/BCGColor.php');
require('class/BCGDrawing.php');
// Including the barcode technology
include('class/BCGcode39.barcode.php');
include_once ("../../include/mcglobal.inc.php");
// Check HTTP-Parameters
getSecHttpVars("1",array("text"));
// Loading Font
$font = new BCGFont('./class/font/Arial.ttf', 18);
// The arguments are R, G, B for color.
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);
$code = new BCGcode39();
$code->setScale(2); // Resolution
$code->setThickness(30); // Thickness
$code->setForegroundColor($color_black); // Color of bars
$code->setBackgroundColor($color_white); // Color of spaces
$code->setFont($font); // Font (or 0)
$code->parse($text); // Text
/* Here is the list of the arguments
1 - Filename (empty : display on screen)
2 - Background color */
$drawing = new BCGDrawing('', $color_white);
$drawing->setBarcode($code);
$drawing->draw();
// Header that says it is an image (remove it if you save the barcode to a file)
header('Content-Type: image/png');
// Draw (or save) the image into PNG format.
$drawing->finish($drawing->IMG_FORMAT_PNG);
?>

View File

@@ -0,0 +1,691 @@
<?php
//////////////////////////////////////////////////////////////////////
// table.class.php
//--------------------------------------------------------------------
//
// Class Table - Don't modify this file !
//
//--------------------------------------------------------------------
// Revision History
// $Id: LSTable.php,v 1.3 2008/07/10 04:23:26 jsgoupil Exp $
//--------------------------------------------------------------------
// Copyright (C) Jean-Sebastien Goupil
// http://www.barcodephp.com
//--------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
define( 'TABLE_DEFAULT_ROW_HIDDEN', FALSE );
define( 'TABLE_DEFAULT_COL_HIDDEN', FALSE );
define( 'TABLE_DEFAULT_CELL_VALUE', '&nbsp;' ); // If '&nbsp;', a cell will appear, if NULL, no cell will appear
define( 'TABLE_DEFAULT_TEMPLATE', 'tpl_LS' );
include( 'Table_template.php' );
class LSTable {
// PRIVATE ARGUMENTS
var $template; // string
var $numRows, $numCols; // int
var $title; // string
var $text = array(); // string
var $cellsAttributes = array(), $rowsAttributes = array(); // string
var $hiddenRows = array(), $hiddenCols = array(); // bool
var $width; // string
var $temp_col; // int
var $temp_ascending; // bool
// PUBLIC FUNCTIONS
/**
* @return
* @param int $numRows
* @param int $numCols
* @param string $width
* @param object $parent
* @desc Constructor. You can put a $parent object. This will search the first empty place into the parent.
**/
function LSTable ( $numRows, $numCols, $width, &$parent ) {
$this->numRows = intval( $numRows );
$this->numCols = intval( $numCols );
for( $i = 0; $i < $numRows; $i++ )
$this->_setVariable( $i );
for( $i = 0; $i < $numCols; $i++ )
$this->hiddenCols[ $i ] = TABLE_DEFAULT_COL_HIDDEN;
$this->title = '';
$this->width = strval( $width );
if( defined( 'TABLE_DEFAULT_TEMPLATE' ) )
$this->setTemplate( TABLE_DEFAULT_TEMPLATE );
// We look for an empty place if $parent isn't null
if( is_object( $parent ) ) {
$stop = false;
for( $i = 0; $i < $parent->numRows; $i++ ) {
for( $j = 0; $j < $parent->numCols; $j++ ) {
if( $parent->text[ $i ][ $j ] == TABLE_DEFAULT_CELL_VALUE ) {
$parent->text[ $i ][ $j ] =& $this;
$stop = true;
}
if( $stop == true )
break;
}
if( $stop == true )
break;
}
}
}
// No destructor for PHP4
//function __destruct() {
//
//}
/**
* @return void
* @param int $row
* @param int $col
* @param mixed $string
* @desc Writes Text or Object into $row and $col.
**/
function setText ( $row, $col, $string ) {
if( is_int( $row ) && is_int( $col ) )
if( $row < $this->numRows && $col < $this->numCols )
$this->text[ $row ][ $col ] = $string;
}
/**
* @return void
* @param int $row
* @param int $col
* @param string $attrib
* @param mixed $value
* @desc Adds a Cell Attribute at $row and $col.
**/
function addCellAttribute ( $row, $col, $attrib, $value ) {
if( is_int( $row ) && is_int( $col ) && is_string( $attrib ) )
if( $row < $this->numRows && $col < $this->numCols )
$this->cellsAttributes[ $row ][ $col ][ strtolower( $attrib ) ] = $value;
}
/**
* @return void
* @param int $row
* @param int $col
* @param string $attrib
* @desc Deletes a Cell Attribute at $row and $col.
**/
function delCellAttribute ( $row, $col, $attrib ) {
if( is_int( $row ) && is_int( $col ) && is_string( $attrib ) )
if( $row < $this->numRows && $col < $this->numCols )
unset( $this->cellsAttributes[ $row ][ $col ][ strtolower( $attrib ) ] );
}
/**
* @return void
* @param int $row
* @param string $attrib
* @param mixed $value
* @desc Adds a Row Attribute at $row. Will be located in TR.
**/
function addRowAttribute ( $row, $attrib, $value ) {
if( is_int( $row ) && is_string( $attrib ) )
if( $row < $this->numRows )
$this->rowsAttributes[ $row ][ strtolower( $attrib ) ] = $value;
}
/**
* @return void
* @param int $row
* @param string $attrib
* @desc Deletes a Row Attribute at $row.
**/
function delRowAttribute ( $row, $attrib ) {
if( is_int( $row ) && is_string( $attrib ) )
if( $row < $this->numRows )
unset( $this->rowsAttributes[ $row ][ strtolower( $attrib ) ] );
}
/**
* @return void
* @param int $row
* @param string $attrib
* @param mixed $value
* @desc Adds a Cell Attribute in all cells located on $row row.
**/
function addAllCellsInRowAttribute ( $row, $attrib, $value ) {
if( is_int( $row ) && is_string( $attrib ) )
if( $row < $this->numRows )
for( $i = 0; $i < $this->numCols; $i++ )
$this->cellsAttributes[ $row ][ $i ][ strtolower( $attrib ) ] = $value;
}
/**
* @return void
* @param int $col
* @param string $attrib
* @param mixed $value
* @desc Adds a Cell Attribute in all cells located on $col column.
**/
function addAllCellsInColAttribute ( $col, $attrib, $value ) {
if( is_int( $col ) && is_string( $attrib ) )
if( $col < $this->numCols )
for( $i = 0; $i < $this->numRows; $i++ )
$this->cellsAttributes[ $i ][ $col ][ strtolower( $attrib ) ] = $value;
}
/**
* @return void
* @param callback $template
* @desc Sets Template (Class)
**/
function setTemplate ( $template ) {
if( is_string( $template ) )
if( class_exists( $template ) )
$this->template = strval( $template );
}
/**
* @return string
* @desc Returns current Template
**/
function template () {
return $this->template;
}
/**
* @return mixed
* @param int $row
* @param int $col
* @desc Returns the text or object contained into $row and $col
**/
function text ( $row, $col ) {
if( is_int( $row ) && is_int( $col ) )
if( $row < $this->numRows && $col < $this->numCols )
return $this->text[ $row ][ $col ];
return FALSE;
}
/**
* @return void
* @param int $row
* @param int $col
* @desc Clears the cell located into $row and $col. Keeps the Cell.
*/
function clearCell ( $row, $col ) {
if( is_int( $row ) && is_int( $col ) ) {
if( $row < $this->numRows && $col < $this->numCols ) {
$this->text[ $row ][ $col ] = TABLE_DEFAULT_CELL_VALUE;
unset( $this->cellsAttributes[ $row ][ $col ] );
$this->cellsAttributes[ $row ][ $col ] = array();
}
}
}
/**
* @return int
* @desc Returns the number of Rows
**/
function numRows () {
return $this->numRows;
}
/**
* @return int
* @desc Returns the number of Columns
**/
function numCols () {
return $this->numCols;
}
/**
* @return void
* @param int $col
* @param bool $ascending
* @desc Sorts table based on $col.
**/
function sortColumn ( $col, $ascending = TRUE ) {
if( is_int( $col ) && is_bool( $ascending ) ) {
if( $col < $this->numCols ) {
$this->temp_col = $col;
$this->temp_ascending = $ascending;
$this->_sort_merge( $this->text );
}
}
}
/**
* @return void
* @param int $r
* @desc Sets the number of rows of the table.
**/
function setNumRows ( $r ) {
if( is_int( $r ) )
if( $r >= 0 )
if( $r > $this->numRows )
$this->insertRows( $this->numRows, $r - $this->numRows );
elseif( $r < $this->numRows )
for( $i = $this->numRows; $i > $r; $i-- )
$this->removeRow( $i - 1 );
}
/**
* @return void
* @param int $r
* @desc Sets the number of columns of the table.
**/
function setNumCols ( $r ) {
if( is_int( $r ) )
if( $r >= 0 )
if( $r > $this->numCols )
$this->insertColumns( $this->numCols, $r - $this->numCols );
elseif( $r < $this->numCols )
for( $i = $this->numCols; $i > $r; $i-- )
$this->removeColumn( $i - 1 );
}
/**
* @return void
* @param int $row
* @desc Hides a $row from table
**/
function hideRow ( $row ) {
if( is_int( $row ) )
if( $row < $this->numRows )
$this->hiddenRows[ $row ] = TRUE;
}
/**
* @return void
* @param int $col
* @desc Hides a $col from table
**/
function hideColumn ( $col ) {
if( is_int( $col ) )
if( $col < $this->numCols )
$this->hiddenCols[ $col ] = TRUE;
}
/**
* @return void
* @param int $row
* @desc Shows a $row from table
**/
function showRow ( $row ) {
if( is_int( $row ) )
if( $row < $this->numRows )
$this->hiddenRows[ $row ] = FALSE;
}
/**
* @return void
* @param int $col
* @desc Shows a $col from table
**/
function showColumn ( $col ) {
if( is_int( $col ) )
if( $col < $this->numCols )
$this->hiddenCols[ $col ] = FALSE;
}
/**
* @return bool
* @param int $row
* @desc Returns TRUE if a row is hidden.
**/
function isRowHidden ( $row ) {
if( is_int( $row ) )
if( $row < $this->numRows )
return $this->hiddenRows[ $row ];
return FALSE;
}
/**
* @return bool
* @param int $col
* @desc Returns TRUE if a col is hidden.
**/
function isColumnHidden ( $col ) {
if( is_int( $col ) )
if( $col < $this->numCols )
return $this->hiddenCols[ $col ];
return FALSE;
}
/**
* @return void
* @param int $row1
* @param int $row2
* @param bool $swapAttributes
* @desc Swaps 2 rows. Swaps attributes if $switchAttributes is TRUE.
**/
function swapRows ( $row1, $row2, $swapAttributes = FALSE ) {
if( is_int( $row1 ) && is_int( $row2 ) && is_bool( $swapAttributes ) ) {
if( $row1 < $this->numRows && $row2 < $this->numRows ) {
$temp =& $this->text[ $row1 ];
$this->text[ $row1 ] =& $this->text[ $row2 ];
$this->text[ $row2 ] =& $temp;
if( $swapAttributes == TRUE ) {
$temp2 = $this->cellsAttributes[ $row1 ];
$this->cellsAttributes[ $row1 ] = $this->cellsAttributes[ $row2 ];
$this->cellsAttributes[ $row2 ] = $temp2;
$temp2 = $this->rowsAttributes[ $row1 ];
$this->rowsAttributes[ $row1 ] = $this->rowsAttributes[ $row2 ];
$this->rowsAttributes[ $row2 ] = $temp2;
}
}
}
}
/**
* @return void
* @param int $col1
* @param int $col2
* @param bool $swapAttributes
* @desc Swaps 2 cols. Swaps attributes if $switchAttributes is TRUE.
**/
function swapColumns ( $col1, $col2, $swapAttributes = FALSE ) {
if( is_int( $col1 ) && is_int( $col2 ) && is_bool( $swapAttributes ) ) {
if( $col1 < $this->numCols && $col2 < $this->numCols ) {
for( $i = 0; $i < $this->numRows; $i++ ){
$temp =& $this->text[ $i ][ $col1 ];
$this->text[ $i ][ $col1 ] =& $this->text[ $i ][ $col2 ];
$this->text[ $i ][ $col2 ] =& $temp;
if( $swapAttributes == TRUE ) {
$temp2 = $this->cellsAttributes[ $i ][ $col1 ];
$this->cellsAttributes[ $i ][ $col1 ] = $this->cellsAttributes[ $i ][ $col2 ];
$this->cellsAttributes[ $i ][ $col2 ] = $temp2;
}
}
}
}
}
/**
* @return void
* @param int $row1
* @param int $col1
* @param int $row2
* @param int $col2
* @param bool $swapAttributes
* @desc Swaps 2 cells. Swaps attributes if $switchAttributes is TRUE.
**/
function swapCells ( $row1, $col1, $row2, $col2, $swapAttributes = FALSE ) {
if( is_int( $row1 ) && is_int( $col1 ) && is_int( $row2 ) && is_int( $col2 ) && is_bool( $swapAttributes ) ) {
if( $row1 < $this->numRows && $col1 < $this->numCols && $row2 < $this->numRows && $col2 < $this->numCols ) {
$temp =& $this->text[ $row1 ][ $col1 ];
$this->text[ $row1 ][ $col1 ] =& $this->text[ $row2 ][ $col2 ];
$this->text[ $row2 ][ $col2 ] =& $temp;
if( $swapAttributes == TRUE ) {
$temp2 = $this->cellsAttributes[ $row1 ][ $col1 ];
$this->cellsAttributes[ $row1 ][ $col1 ] = $this->cellsAttributes[ $row2 ][ $col2 ];
$this->cellsAttributes[ $row2 ][ $col2 ] = $temp2;
}
}
}
}
/**
* @return void
* @param int $row
* @param int $count
* @desc Inserts $count row at $row position.
**/
function insertRows ( $row, $count = 1 ) {
if( is_int( $row ) && is_int( $count ) ) {
if( $row >= 0 && $row <= $this->numRows ) {
for( $i = 0; $i < $count; $i++) {
array_splice( $this->text, $row, 0, '' );
array_splice( $this->hiddenRows, $row, 0, FALSE );
array_splice( $this->cellsAttributes, $row, 0, FALSE );
array_splice( $this->rowsAttributes, $row, 0, FALSE );
$this->_setVariable( $row );
$this->numRows += 1;
}
}
}
}
/**
* @return void
* @param int $col
* @param int $count
* @desc Inserts $count columns at $col position.
**/
function insertColumns ( $col, $count = 1 ) {
if( is_int( $col ) && is_int( $count ) ) {
if( $col >= 0 && $col <= $this->numCols ) {
for( $i = 0; $i < $this->numRows; $i++ ) {
$temp_text = array();
$temp_attributes = array();
reset($this->text[ $i ]);
for( $j = 0; $j <= $this->numCols; $j++ ) {
if( $col == $j ) {
for( $k = 0; $k < $count; $k++ ){
$temp_text[] = '';
$temp_attributes[] = array();
}
}
if( $j == $this->numCols )
break;
$temp_text[] = $this->text[ $i ][ $j ];
$temp_attributes[] = $this->cellsAttributes[ $i ][ $j ];
}
$this->text[ $i ] = $temp_text;
$this->cellsAttributes[ $i ] = $temp_attributes;
}
for( $i = 0; $i < $count; $i++ )
array_splice( $this->hiddenCols, $col, 0, FALSE );
$this->numCols += $count;
}
}
}
/**
* @return void
* @param int $row
* @desc Removes $row.
**/
function removeRow ( $row ) {
if( is_int( $row ) ) {
if( $row < $this->numRows ) {
array_splice( $this->text, $row, 1 );
array_splice( $this->hiddenRows, $row, 1 );
array_splice( $this->cellsAttributes, $row, 1 );
array_splice( $this->rowsAttributes, $row, 1 );
$this->numRows -= 1;
}
}
}
/**
* @return void
* @param int $col
* @desc Removes $col.
**/
function removeColumn ( $col ) {
if( is_int( $col ) ) {
if( $col < $this->numCols ) {
for( $i = 0; $i < $this->numRows; $i++ ) {
$temp_text = array();
$temp_attributes = array();
reset($this->text[ $i ]);
while ( list( $key, ) = each( $this->text[ $i ] ) ) {
if( $key != $col ) {
$temp_text[] = $this->text[ $i ][ $key ];
$temp_attributes[] = $this->cellsAttributes[ $i ][ $key ];
}
}
$this->text[ $i ] = $temp_text;
$this->cellsAttributes[ $i ] = $temp_attributes;
}
array_splice( $this->hiddenCols, $col, 1 );
$this->numCols -= 1;
}
}
}
/**
* @return void
* @param int $width
* @desc Sets Table Width.
**/
function setWidth ( $width ) {
if( is_string( $width ) )
$this->width = strval( $width );
}
/**
* @return string
* @desc Returns Table Width.
**/
function width () {
return $this->width;
}
/**
* @return void
* @param int $title
* @desc Sets Table Title.
**/
function setTitle ( $title ) {
if( is_string( $title ) )
$this->title = strval( $title );
}
/**
* @return string
* @desc Returns Table Title.
**/
function title () {
return $this->title;
}
/**
* @return void
* @desc Displays the table with its cells.
**/
function draw () {
if( $this->template != '' ) {
$tpl = new $this->template;
$tpl->__header( $this->width, $this->title );
$this->_check_rowcol_span();
for( $i = 0; $i < $this->numRows; $i++ ) {
if( $this->hiddenRows[ $i ] == FALSE ) {
$tpl->__row_start( $this->rowsAttributes[ $i ] );
for( $j = 0; $j < $this->numCols; $j++ ) {
if( $this->hiddenCols[ $j ] == FALSE ) {
if( $this->text[ $i ][ $j ] !== NULL ) {
if( is_object( $this->text[ $i ][ $j ] ) ) {
$tpl->__cell_start( '', $this->cellsAttributes[ $i ][ $j ] );
$this->text[ $i ][ $j ]->draw();
}
else
$tpl->__cell_start( $this->text[ $i ][ $j ], $this->cellsAttributes[ $i ][ $j ] );
$tpl->__cell_stop( $this->text[ $i ][ $j ], $this->cellsAttributes[ $i ][ $j ] );
}
}
}
$tpl->__row_stop( $this->rowsAttributes[ $i ] );
}
}
$tpl->__footer( $this->width, $this->title );
}
}
// PRIVATE FUNCTIONS
/**
* @return void
* @desc Sets NULL to cells if colspan or rowspan go on the cells
**/
function _check_rowcol_span() {
for( $i = 0; $i < $this->numRows; $i++ ) {
for( $j = 0; $j < $this->numCols; $j++ ) {
if( isset( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] ) )
if( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] > 0 )
for( $z = 1; $z < intval( $this->cellsAttributes[ $i ][ $j ][ 'colspan' ] ); $z++ )
$this->text[ $i ][ $j + $z ] = NULL;
if( isset( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] ) )
if( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] > 0 )
for( $z = 1; $z < intval( $this->cellsAttributes[ $i ][ $j ][ 'rowspan' ] ); $z++ )
$this->text[ $i + $z ][ $j ] = NULL;
}
}
}
/**
* @return void
* @param int $r
* @desc Sets Default Variables for row $r.
**/
function _setVariable ( $r ) {
$this->text[ $r ] = array_fill( 0, $this->numCols, TABLE_DEFAULT_CELL_VALUE );
$this->cellsAttributes[ $r ] = array_fill( 0, $this->numCols, array() );
$this->rowsAttributes[ $r ] = array();
$this->hiddenRows[ $r ] = TABLE_DEFAULT_ROW_HIDDEN;
}
/**
* @return void
* @param int $r
* @desc Unsets Default Variables for row $r.
**/
function _unsetVariable ( $r ) {
unset( $this->text[ $r ] );
unset( $this->cellsAttributes[ $r ] );
unset( $this->rowsAttributes[ $r ] );
unset( $this->hiddenRows[ $r ] );
}
/**
* @return void
* @param string $tab
* @desc Merge Function
**/
function _sort_merge ( &$tab ) {
if( count( $tab ) <= 1 ) return;
else {
$tab1 = array();
$tab2 = array();
for( $i = 0; $i < count( $tab ); $i++) {
if( $i < ( count( $tab ) ) / 2 )
$tab1[] = $tab[ $i ];
else
$tab2[] = $tab[ $i ];
}
$this->_sort_merge( $tab1 );
$this->_sort_merge( $tab2 );
$this->_merge_all( $tab1, $tab2, $tab );
}
}
/**
* @return void
* @param string $tab1
* @param string $tab2
* @param string $tab
* @desc Merge Function
**/
function _merge_all ( $tab1, $tab2, &$tab ) {
$i = 0;
$i1 = $i2 = 0;
while( $i1 < count( $tab1 ) && $i2 < count( $tab2 ) ) {
if( strcmp( $tab1[ $i1 ][ $this->temp_col ], $tab2[ $i2 ][ $this->temp_col ] ) == (($this->temp_ascending==TRUE)?-1:1) )
$tab[ $i ] = $tab1[ $i1++ ];
else
$tab[ $i ] = $tab2[ $i2++ ];
$i++;
}
while( $i1 < count( $tab1 ) ) {
$tab[ $i ] = $tab1[ $i1++ ];
$i++;
}
while( $i2 < count( $tab2 ) ) {
$tab[ $i ] = $tab2[ $i2++ ];
$i++;
}
}
}
?>

View File

@@ -0,0 +1,71 @@
<?php
class tpl_LS {
function __header ( $width, $title ) {
echo '<table width="'.$width.'" border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#004163" class="tableline"><tr><th><u>'.$title.'</u>'."\n".'</th></tr><tr><td>'."\n".'<table width="100%" border="0" cellpadding="4" cellspacing="1" align="center">';
}
function __footer ( $width, $title ) {
echo '</table>'."\n".'</td></tr></table>'."\n";
}
function __row_start ( $attributes ) {
$code = '';
$found_class = false;
reset( $attributes );
while( list( $key, $value ) = each( $attributes ) ) {
$code .= ' '.$key.'="'.$value.'"';
if( $key == 'class' )
$found_class = true;
}
if( $found_class=== false )
$code .= ' class="'.next_color().'"';
echo '<tr'.$code.'>';
}
function __row_stop ( $attributes ) {
echo '</tr>';
}
function __cell_start ( $text, $attributes ) {
$code = '';
reset( $attributes );
while( list( $key, $value ) = each( $attributes ) )
$code .= ' '.$key.'="'.$value.'"';
echo '<td'.$code.'>'.$text;
}
function __cell_stop ( $text, $attributes ) {
echo '</td>';
}
}
class tpl_BLANK {
function __header ( $width, $title ) {
echo '<table width="'.$width.'" border="0" cellpadding="0" cellspacing="0" align="center">';
}
function __footer ( $width, $title ) {
echo '</table>';
}
function __row_start ( $attributes ) {
echo '<tr>';
}
function __row_stop ( $attributes ) {
echo '</tr>';
}
function __cell_start ( $text, $attributes ) {
$code = '';
reset( $attributes );
while( list( $key, $value ) = each( $attributes ) )
$code .= ' '.$key.'="'.$value.'"';
echo '<td'.$code.'>'.$text;
}
function __cell_stop ( $text, $attributes ) {
echo '</td>';
}
}
?>

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '$', ':', '/', '.', '+', 'A', 'B', 'C', 'D');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Known also as Ames Code, NW-7, Monarch, 2 of 7, Rationalized Codabar.</li><li>Codabar was developed in 1972 by Pitney Bowes, Inc.</li><li>This symbology is useful to encode digital information. It is a self-checking code, there is no check digit.</li><li>Codabar is used by blood bank, photo labs, library, FedEx...</li><li>Coding can be with an unspecified length composed by numbers, plus and minus sign, colon, slash, dot, dollar.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i].'" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Known also as USD-8.</li><li>Code 11 was developed in 1977 as a high-density numeric symbology.</li><li>Used to identify telecommunications equipment.</li><li>Code 11 is a numeric symbology and its character set consists of 10 digital characters and the dash symbol (-).</li><li>There is a "C" check digit. If the length of encoded message is greater thant 10, a "K" check digit may be used.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,57 @@
<?php
define('IN_CB', true);
include('header.php');
$vals = array();
for($i = 0; $i <= 127; $i++) {
$vals[] = '%' . sprintf('%02X', $i);
}
$keys = array(
'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'TAB', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', 'FS', 'GS', 'RS', 'US',
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'DEL'
);
if($a2 === '') {
$a2 = 'NULL';
}
$n = $table->numRows();
$table->insertRows($n, 4);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Starts With');
$text2display = '<select size="1" name="a2"><option value="NULL"';
if($a2=='NULL') {
$text2display .= ' selected="selected"';
}
$text2display .= '>Auto</option><option value="A"';
if($a2 === 'A') {
$text2display .= ' selected="selected"';
}
$text2display .= '>Code 128-A</option><option value="B"';
if($a2 === 'B') {
$text2display .= ' selected="selected"';
}
$text2display .= '>Code 128-B</option><option value="C"';
if($a2 === 'C') {
$text2display .= ' selected="selected"';
}
$text2display .= '>Code 128-C</option></select>';
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . htmlentities($keys[$i]) . '" style="width:37px;padding:0px;" onclick="newkey(this.form,unescape(\'' . $vals[$i] . '\'))" /> ';
}
$table->setText($n + 2, 1, $text2display);
$table->setText($n + 3, 0, 'Explanation');
$table->setText($n + 3, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Code 128 is a high-density alphanumeric symbology.</li><li>Used extensively worldwide.</li><li>Code 128 is designed to encode 128 full ASCII characters.</li><li>The symbology includes a checksum digit.</li><li>Code 128A handles capital letters<br />Code 128B handles capital letters and lowercase<br />Code 128C handles group of 2 numbers</li><li>Your browser may not be able to write the special characters (NUL, SOH, etc.) but you can write them with the code.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,34 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%');
$n = $table->numRows();
$table->insertRows($n, 4);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, '<label for="checksum">Checksum</label>');
$text2display = '<input type="checkbox" name="a1" id="checksum" value="1"';
if($a1 == 1) {
$text2display .= ' checked="checked"';
}
$text2display .= ' />';
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 2, 1, $text2display);
$table->setText($n + 3, 0, 'Explanation');
$table->setText($n + 3, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Known also as USS Code 39, 3 of 9.</li><li>Code 39 can encode alphanumeric characters.</li><li>The symbology is used in non-retail environment.</li><li>Code 39 is designed to encode 26 upper case letters, 10 digits and 7 special characters.</li><li>Code 39 has a checksum but it\'s rarely used.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,43 @@
<?php
define('IN_CB', true);
include('header.php');
$vals = array();
for($i = 0; $i <= 127; $i++) {
$vals[] = '%' . sprintf('%02X', $i);
}
$keys = array(
'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'TAB', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', 'FS', 'GS', 'RS', 'US',
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'DEL'
);
$n = $table->numRows();
$table->insertRows($n, 4);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, '<label for="checksum">Checksum</label>');
$text2display = '<input type="checkbox" name="a1" id="checksum" value="1"';
if($a1==1) {
$text2display .= ' checked="checked"';
}
$text2display .= ' />';
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . htmlentities($keys[$i]) . '" style="width:37px;padding:0px;" onclick="newkey(this.form,unescape(\'' . $vals[$i] . '\'))" /> ';
}
$table->setText($n + 2, 1, $text2display);
$table->setText($n + 3, 0, 'Explanation');
$table->setText($n + 3, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Supports the ASCII 0 to 127</li><li>This mode is "optional" for Code 39, you have to specify your reader that you have extended code.</li><li>Your browser may not be able to write the special characters (NUL, SOH, etc.) but you can write them with the code.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,36 @@
<?php
define('IN_CB', true);
include('header.php');
$vals = array();
for($i = 0; $i <= 127; $i++) {
$vals[] = '%' . sprintf('%02X', $i);
}
$keys = array(
'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'TAB', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', 'FS', 'GS', 'RS', 'US',
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'DEL'
);
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n ,0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . htmlentities($keys[$i]) . '" style="width:37px;padding:0px;" onclick="newkey(this.form,unescape(\'' . $vals[$i] . '\'))" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Known also as USS Code 93.</li><li>Code 93 was designed to provide a higher density and data security enhancement to Code39.</li><li>Used primarily by Canadian postal office to encode supplementary delivery information.</li><li>Similar to Code 39, Code 93 has the same 43 characters plus 5 special ones to encode the ASCII 0 to 127.</li><li>This symbology composed of 2 check digits ("C" and "K").</li><li>Your browser may not be able to write the special characters (NUL, SOH, etc.) but you can write them with the code.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,3 @@
<?php
$class_dir = '../include/barcode_php7/class';
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>EAN means Internal Article Numbering.</li><li>It is an extension of UPC-A to include the country information.</li><li>Used with consumer products internationally.</li><li>Composed by 2 number system, 5 manufacturer code, 5 product code and 1 check digit.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>EAN-8 is a short version of EAN-13.</li><li>Composed by 7 digits and 1 check digit.</li><li>There is no conversion available between EAN-8 and EAN-13.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,11 @@
<?php
if(!defined('IN_CB'))die('You are not allowed to access to this page.');
?>
<p style="text-align:center;font-size:10px">
All Rights Reserved &copy; 2004-2010 <a href="http://www.barcodephp.com" target="_blank">Barcode Generator</a> PHP4-v<?php echo constant('VERSION'); ?>
<br />by Jean-Sébastien Goupil
</p>
</body>
</html>

View File

@@ -0,0 +1,188 @@
<?php
if(!defined('IN_CB')) die('You are not allowed to access to this page.');
/**
* Displays Select Code bar Box
*
* @param string $filename
*/
function display_select($filename) {
$table_value = array('codabar', 'code11', 'code39', 'code39extended', 'code93', 'code128', 'ean8', 'ean13', 'gs1128', 'isbn', 'i25', 's25', 'msi', 'upca', 'upce', 'upcext2', 'upcext5', 'postnet', 'othercode');
$table_text = array('Codabar', 'Code 11', 'Code 39', 'Code 39 Extended', 'Code 93', 'Code 128', 'EAN-8', 'EAN-13', 'GS1-128 (EAN-128)', 'ISBN-10 / ISBN-13', 'Interleaved 2 of 5', 'Standard 2 of 5', 'MSI Plessey', 'UPC-A', 'UPC-E', 'UPC Extension 2 Digits', 'UPC Extension 5 Digits', 'PostNet', 'Other Barcode');
$text2display = '';
$text2display .= '<select name="barcode_type" size="1" onchange="location.href=barcode_type.options[barcode_type.selectedIndex].value + \'.php\'" style="width: 300px">';
$c = count($table_value);
for ($i = 0; $i < $c; $i++) {
$text2display .= '<option value="' . $table_value[$i] . '"';
if ($table_value[$i] === $filename) {
$text2display .= ' selected="selected"';
}
$text2display .= '>' . $table_text[$i] . '</option>';
}
$text2display .= '</select>';
return $text2display;
}
/**
* Displays the output (PNG, JPEG, GIF)
*
* @param int $number
*/
function display_output($number) {
$table_value = array('1', '2', '3');
$table_text = array('Portable Network Graphics (PNG)', 'Joint Photographic Experts Group (JPEG)', 'Graphics Interchange Format (GIF)');
$text2display = '';
$text2display .= '<select onchange="if(this.value==1||this.value==2)disableDPI(false);else disableDPI(true);" name="output" size="1" style="width:300px">';
$c = count($table_value);
for ($i = 0; $i < $c; $i++) {
$text2display .= '<option value="' . $table_value[$i] . '"';
if (intval($table_value[$i]) === intval($number)) {
$text2display .= ' selected="selected"';
}
$text2display .= '>' . $table_text[$i] . '</option>';
}
$text2display .= '</select>';
return $text2display;
}
/**
* Displays the DPI
*
* @param int $output
* @param float $dpi
*/
function display_dpi($output, $dpi) {
$disabled = ($output != 1 && $output != 2);
$disableText = $disabled ? ' disabled="disabled"' : '';
$showExplain = $disabled ? '' : ' display: none;';
return '<script type="text/javascript">
function disableDPI(disable){
document.getElementById("dpi").disabled = disable;
document.getElementById("dpi_explain").style.display = disable ? "inline" : "none";
}
</script><input type="text" id="dpi" name="dpi" value="' . $dpi . '" size="5"' . $disableText . ' /> <span id="dpi_explain" style="color: red;' . $showExplain . '">DPI is available only for PNG and JPEG.</span><div style="font-size: 8pt;">If you set <i>null</i>, the image generation will be faster and will be the same as 72dpi.</div>';
}
/**
* Displays the thickness of the bars
*
* @param int $number
*/
function display_thickness($number) {
return '<input type="text" name="thickness" value="' . $number . '" size="5" />';
}
/**
* Displays the resolution of the code
*
* @param int $number
*/
function display_res($number) {
$table = new LSTable(1, 3, '100%', $null);
$table->setTemplate('tpl_BLANK');
for ($i = 1; $i <= 3; $i++) {
$text2display = '';
$text2display .= '<input type="radio" id="res' . $i . '" name="res" value="' . $i . '"';
if ($number === $i) {
$text2display .= ' checked="checked"';
}
$text2display .= ' /> <label for="res' . $i . '">' . $i . '</label>';
$table->setText(0, $i - 1, $text2display);
}
return $table;
}
/**
* Displays the rotation
*
* @param int $rotation
*/
function display_rotation($rotation) {
$availableRotation = array(0, 90, 180, 270);
$c = count($availableRotation);
$table = new LSTable(1, $c, '100%', $null);
$table->setTemplate('tpl_BLANK');
for ($i = 0; $i < $c; $i++) {
$text2display = '';
$text2display .= '<input type="radio" id="rotation' . $i . '" name="rotation" value="' . $availableRotation[$i] . '"';
if ($rotation == $availableRotation[$i]) {
$text2display .= ' checked="checked"';
}
$text2display .= ' /> <label for="rotation' . $i . '">' . $availableRotation[$i] . '&deg;</label>';
$table->setText(0, $i, $text2display);
}
return $table;
}
/**
* Displays the fontsize of the label
*
* @param int $number
*/
function display_font($family, $size) {
if($family === '0') $family = 'Arial.ttf';
$text2display = '';
$text2display .= '<select name="font_family" size="1" style="width:130px">';
$text2display .= '<option value="-1">No Text</option>';
// List of all fonts available
$f = listfonts();
$c = count($f);
for ($i = 0; $i < $c; $i++) {
$text2display .= '<option value="' . $f[$i] . '"';
if ($f[$i] === $family) {
$text2display .= ' selected="selected"';
}
$text2display .= '>' . $f[$i] . '</option>';
}
$text2display .= '</select>';
$text2display .= ' ';
$text2display .= '<input type="text" name="font_size" value="' . $size . '" size="3" style="width:30px" />';
return $text2display;
}
/**
* Displays the textbox
*
* @param string $text
*/
function display_text($text) {
return '<input type="text" name="text2display" value="' . $text . '" size="20" />';
}
/**
* Returns the next class for a table line.
*
* @param int $restart If 1, then restart color to 1
* @return string
*/
function next_color($restart = 0) {
global $sys_conf;
static $color = 0;
if ($restart === 1) { $color = NULL; }
if ($color === 1) { $couleur = 'row2'; $color = 2; }
else { $couleur = 'row1'; $color = 1; }
return $couleur;
}
/**
* Returns the font available for drawing
*
* @return string[]
*/
function listfonts() {
global $class_dir;
$array = array();
if (($handle = opendir($class_dir . '/font')) !== false) {
while (($file = readdir($handle)) !== false) {
if(substr($file, -4, 4) === '.ttf') {
$array[] = $file;
}
}
}
closedir($handle);
return $array;
}
?>

View File

@@ -0,0 +1,46 @@
var nbIdentifiers = 0;
var idRow = 0;
function addIdentifier(id) {
nbIdentifiers++;
idRow++;
if(document.getElementById('identifiersContainer').style.display === 'none') {
document.getElementById('identifiersContainer').style.display = '';
}
if(document.getElementById('identifiersButton').style.display === 'none') {
document.getElementById('identifiersButton').style.display = '';
}
var newIdentifier = document.createElement("DIV");
newIdentifier.id = 'identifier_' + idRow;
newIdentifier.style.height = '25px';
newIdentifier.style.position = 'relative';
newIdentifier.style.marginTop = '2px';
newIdentifier.innerHTML = '<input type="text" name="textTemp[0][]" value="' + id + '" style="width:40px;" /> - <input type="text" name="textTemp[1][]" style="width:295px;" /><a href="javascript:removeIdentifier(' + idRow + ');"><img src="delete.png" alt="Delete" style="border:0px; margin-left:5px; margin-top:5px;" /></a>';
document.getElementById('identifiersContainer').appendChild(newIdentifier);
document.getElementById('identifier').value = '';
}
function removeIdentifier(id) {
nbIdentifiers--;
document.getElementById('identifiersContainer').removeChild(document.getElementById('identifier_' + id));
if(nbIdentifiers === 0) {
document.getElementById('identifiersButton').style.display = 'none';
document.getElementById('identifiersContainer').style.display = 'none';
}
}
function sendForm() {
var text2display = document.getElementsByName("text2display");
var barcodeDrawer = document.getElementsByName("barcode_drawer");
var gs1128Id = document.getElementsByName("textTemp[0][]");
var gs1128Content = document.getElementsByName("textTemp[1][]");
text2display[0].value = '';
for(var i = 0; i < gs1128Id.length; i++) {
text2display[0].value = text2display[0].value + '(' + gs1128Id[i].value + ')';
text2display[0].value = text2display[0].value + gs1128Content[i].value + unescape('%1D');
}
barcodeDrawer[0].submit();
}

View File

@@ -0,0 +1,212 @@
<?php
define('IN_CB', true);
include('header.php');
$vals = array();
for($i = 0; $i <= 127; $i++) {
$vals[] = '%' . sprintf('%02X', $i);
}
$keys = array(
'NUL', 'SOH', 'STX', 'ETX', 'EOT', 'ENQ', 'ACK', 'BEL', 'BS', 'TAB', 'LF', 'VT', 'FF', 'CR', 'SO', 'SI', 'DLE', 'DC1', 'DC2', 'DC3', 'DC4', 'NAK', 'SYN', 'ETB', 'CAN', 'EM', 'SUB', 'ESC', 'FS', 'GS', 'RS', 'US',
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 'DEL'
);
if($a2 == '') {
$a2 = 'C';
}
$n = $table->numRows();
$table->insertRows($n, 5);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Starts With');
$text2display = '<select size="1" name="a2"><option value="A"';
if($a2 == 'A') {
$text2display .= ' selected="selected"';
}
$text2display .= '>Code 128-A</option><option value="B"';
if($a2 == 'B') {
$text2display .= ' selected="selected"';
}
$text2display .= '>Code 128-B</option><option value="C"';
if($a2 == 'C') {
$text2display .= ' selected="selected"';
}
$text2display .= '>Code 128-C</option></select>';
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . htmlentities($keys[$i]) . '" style="width:37px;padding:0px;" onclick="newkey(this.form,unescape(\'' . $vals[$i] . '\'))" /> ';
}
$table->setText($n + 2, 1, $text2display);
/* Application Identifiers (AIs) */
$table->setText($n + 3, 0, 'Identifiers');
$text2display = '<script type="text/javascript" src="gs1128.js"></script>';
$identifiers = array(
'00' => 'Serial Shipping Container Code (SSCC-18)',
'01' => 'Shipping Container Code (SSC)',
'02' => 'Number of containers',
'10' => 'Batch Number',
'11' => 'Production Date',
'12' => 'Due date',
'13' => 'Packaging Date',
'15' => 'Sell by Date (Quality Control)',
'17' => 'Expiration Date',
'20' => 'Product Variant',
'21' => 'Serial Number',
'240' => 'Additional Product Identification',
'241' => 'Customer part number',
'250' => 'Second Serial Number',
'251' => 'Reference to source entity',
'253' => 'Global Document Type Identifier',
'30' => 'Quantity Each',
'310y' => 'Product Net Weight in kg',
'311y' => 'Product Length/1st Dimension, in meters',
'312y' => 'Product Width/Diameter/2nd Dimension, in meters',
'313y' => 'Product Depth/Thickness/3rd Dimension, in meters',
'314y' => 'Product Area, in square meters',
'315y' => 'Product Volume, in liters',
'316y' => 'product Volume, in cubic meters',
'320y' => 'Product Net Weight, in pounds',
'321y' => 'Product Length/1st Dimension, in inches',
'322y' => 'Product Length/1st Dimension, in feet',
'323y' => 'Product Length/1st Dimension, in yards',
'324y' => 'Product Width/Diameter/2nd Dimension, in inches',
'325y' => 'Product Width/Diameter/2nd Dimension, in feet',
'326y' => 'Product Width/Diameter/2nd Dimension, in yards',
'327y' => 'Product Depth/Thickness/3rd Dimension, in inches',
'328y' => 'Product Depth/Thickness/3rd Dimension, in feet',
'329y' => 'Product Depth/Thickness/3rd Dimension, in yards',
'330y' => 'Container Gross Weight (Kg)',
'331y' => 'Container Length/1st Dimension (Meters)',
'332y' => 'Container Width/Diameter/2nd Dimension (Meters)',
'333y' => 'Container Depth/Thickness/3rd Dimension (Meters)',
'334y' => 'Container Area (Square Meters)',
'335y' => 'Container Gross Volume (Liters)',
'336y' => 'Container Gross Volume (Cubic Meters)',
'337y' => 'Kilograms per square meter',
'340y' => 'Container Gross Weight (Pounds)',
'341y' => 'Container Length/1st Dimension, in inches',
'342y' => 'Container Length/1st Dimension, in feet',
'343y' => 'Container Length/1st Dimension in, in yards',
'344y' => 'Container Width/Diameter/2nd Dimension, in inches',
'345y' => 'Container Width/Diameter/2nd Dimension, in feet',
'346y' => 'Container Width/Diameter/2nd Dimension, in yards',
'347y' => 'Container Depth/Thickness/Height/3rd Dimension, in inches',
'348y' => 'Container Depth/Thickness/Height/3rd Dimension, in feet',
'349y' => 'Container Depth/Thickness/Height/3rd Dimension, in yards',
'350y' => 'Product Area (Square Inches)',
'351y' => 'Product Area (Square Feet)',
'352y' => 'Product Area (Square Yards)',
'353y' => 'Container Area (Square Inches)',
'354y' => 'Container Area (Square Feet)',
'355y' => 'Container Area (Square Yards)',
'356y' => 'Net Weight (Troy Ounces)',
'357y' => 'Kilograms per square meter',
'360y' => 'Product Volume (Quarts)',
'361y' => 'Product Volume (Gallons)',
'362y' => 'Container Gross Volume (Quarts)',
'363y' => 'Container Gross Volume (Gallons)',
'364y' => 'Product Volume (Cubic Inches)',
'365y' => 'Product Volume (Cubic Feet)',
'366y' => 'Product Volume (Cubic Yards)',
'367y' => 'Container Gross Volume (Cubic Inches)',
'368y' => 'Container Gross Volume (Cubic Feet)',
'369y' => 'Container Gross Volume (Cubic Yards)',
'37' => 'Number of Units Contained',
'390y' => 'Amount payable-single monetary area',
'391y' => 'Amount payable with ISO currency code',
'392y' => 'Amount payable for a Variable Measure Trade Item single monetary unit',
'393y' => 'Amount payable for a Variable Measure Trade Item - with ISO currency code',
'400' => 'Customer Purchase Order Number',
'401' => 'Consignment number',
'402' => 'Shipment Identification Number',
'403' => 'Routing code',
'410' => 'Ship To/Deliver To Location Code (EAN13 or DUNS code)',
'411' => 'Bill To/Invoice Location Code (EAN13 or DUNS code)',
'412' => 'Purchase From Location Code (EAN13 or DUNS code)',
'413' => 'Ship for - deliver for - forward to EAN.UCC Global Location Number',
'414' => 'Identification of a physical location EAN.UCC Global Location Number',
'415' => 'EAN.UCC Global Location Number of the invoicing party',
'420' => 'Ship To/Deliver To Postal Code (Single Postal Authority)',
'421' => 'Ship To/Deliver To Postal Code (Multiple Postal Authority)',
'422' => 'Country of origin of a trade item',
'8001' => 'Roll Products - Width/Length/Core Diameter',
'8002' => 'Electronic Serial Number (ESN) for Cellular Phone',
'8003' => 'UPC/EAN Number and Serial Number of Returnable Asset',
'8004' => 'UPC/EAN Serial Identification',
'8005' => 'Price per Unit of Measure',
'8006' => 'Identification of the component of a trade item',
'8007' => 'International Bank Account Number',
'8018' => 'EAN.UCC Global Service Relation Number',
'8020' => 'Payment Slip Reference Number',
'8100' => 'Coupon Extended Code: Number System and Offer',
'8101' => '8101 Coupon Extended Code: Number System, Offer, End of Offer',
'8102' => 'Coupon Extended Code: Number System preceded by 0',
'90' => 'Mutually Agreed Between Trading Partners',
'91' => 'Internal Company Codes',
'92' => 'Internal Company Codes',
'93' => 'Internal Company Codes',
'94' => 'Internal Company Codes',
'95' => 'Internal Company Codes',
'96' => 'Internal Company Codes',
'97' => 'Internal Company Codes',
'98' => 'Internal Company Codes',
'99' => 'Internal Company Codes'
);
$identifiersPost = isset($_POST['textTemp']) ? $_POST['textTemp'] : '';
if(!is_array($identifiersPost)) {
$identifiersPost = '';
}
if($identifiersPost != '') {
$displayDiv = '';
} else {
$displayDiv = 'none';
}
$text2display .= '<select name="identifier" id="identifier" style="width:300px;" onchange="addIdentifier(identifier.options[identifier.selectedIndex].value)">';
$text2display .= '<option value="">Please select an identifier ...</option>';
foreach($identifiers as $id => $identifiers) {
$text2display .= '<option value="' . $id . '">' . $id . ' - ' . $identifiers . '</option>';
}
$text2display .= '</select><div id="identifiersContainer" style="display:' . $displayDiv . '; padding-bottom:5px;">';
if($identifiersPost != '') {
$identifiersIdPost = $identifiersPost[0];
$identifiersContentPost = $identifiersPost[1];
$c = count($identifiersIdPost);
for($i = 0; $i < $c; $i++) {
$text2display .= '<div id="identifier_' . $i . '" style="height:25px; position:relative; margin-top:2px;">';
$text2display .= '<input type="text" name="textTemp[0][]" value="' . $identifiersIdPost[$i] . '" style="width:40px;" /> - <input type="text" name="textTemp[1][]" style="width:295px;" value="' . $identifiersContentPost[$i] . '" /><a href="javascript:removeIdentifier(' . $i . ');"><img src="delete.png" alt="" style="border:0px; margin-left:5px; margin-top:5px;" /></a>';
$text2display .= '</div>';
}
$text2display .= '<script type="text/javascript">var nbIdentifiers = ' . $c . '; var idRow = ' . $c . ';</script>';
}
$text2display .= '</div>';
$text2display .= '<div style="text-align:center;"><input id="identifiersButton" type="button" value="Generate GS1-128 CODE" style="display:' . $displayDiv . '; margin-top:5px;" onclick="sendForm()" /></div>';
$table->setText($n + 3, 1, $text2display);
$table->setText($n + 4, 0, 'Explanation');
$table->setText($n + 4, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Encoded as Code 128.</li><li>The former correct name was UCC/EAN-128.</li><li>Use for shipping containers.</li><li>Based on the GS1 standard.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,107 @@
<?php
if(!defined('IN_CB')) die('You are not allowed to access to this page.');
define('VERSION', '2.2.0');
if(version_compare(phpversion(), '4.3.0', '>=') !== true)
exit('Sorry, but you have to run this script with PHP4.3+... You currently have the version <b>'.phpversion().'</b>.');
if(!function_exists('imagecreate'))
exit('Sorry, make sure you have the GD extension installed before running this script.');
include('config.php');
require('function.php');
include('LSTable.php');
echo '<?xml version="1.0" encoding="iso-8859-1"?>' . "\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Drawing Barcode</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link type="text/CSS" rel="stylesheet" href="./style.css" />
<script language="JavaScript" type="text/javascript">
function newkey(form,variable){
form.text2display.value += variable;
}
function newkeyCode(form,variable){
form.text2display.value += String.fromCharCode(variable);
}
</script>
</head>
<body bgcolor="#ffffff">
<?php
if(version_compare(phpversion(), '5.0.0', '>=') === true)
echo '<i>[WARNING] You currently run this script with PHP5... we advise you to use the PHP5 version of this script if you experience any problems.</i>';
// FileName & Extension
$system_temp_array = explode('/', $_SERVER['PHP_SELF']);
$system_temp_array2 = explode('.', $system_temp_array[count($system_temp_array) - 1]);
$filename = $system_temp_array2[0];
$default_value = array();
$default_value['output'] = 1;
$default_value['dpi'] = 72;
$default_value['thickness'] = 30;
$default_value['res'] = 1;
$default_value['rotation'] = 0.0;
$default_value['font_family'] = '0';
$default_value['font_size'] = 8;
$default_value['text2display'] = '';
$default_value['a1'] = '';
$default_value['a2'] = '';
$default_value['a3'] = '';
$output = intval(isset($_POST['output']) ? $_POST['output'] : $default_value['output']);
$dpi = isset($_POST['dpi']) ? $_POST['dpi'] : $default_value['dpi'];
$thickness = intval(isset($_POST['thickness']) ? $_POST['thickness'] : $default_value['thickness']);
$res = intval(isset($_POST['res']) ? $_POST['res'] : $default_value['res']);
$rotation = isset($_POST['rotation']) ? $_POST['rotation'] : $default_value['rotation'];
$font_family = isset($_POST['font_family']) ? $_POST['font_family'] : $default_value['font_family'];
$font_size = intval(isset($_POST['font_size']) ? $_POST['font_size'] : $default_value['font_size']);
$text2display = isset($_POST['text2display']) ? $_POST['text2display'] : $default_value['text2display'];
$a1 = isset($_POST['a1']) ? $_POST['a1'] : $default_value['a1'];
$a2 = isset($_POST['a2']) ? $_POST['a2'] : $default_value['a2'];
$a3 = isset($_POST['a3']) ? $_POST['a3'] : $default_value['a3'];
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="barcode_drawer" method="post">
<?php
$table = new LSTable(10, 2, '500', $null);
$table->setTitle('Configs for ' . $filename);
$table->addRowAttribute(0, 'class', 'table_title');
$table->addCellAttribute(0, 0, 'colspan', '2');
$table->addCellAttribute(0, 0, 'align', 'center');
$table->setText(0, 0, '<font color="#ffffff"><b>General Configs</b></font>');
$table->addCellAttribute(1, 0, 'width', '100');
$table->setText(1, 0, 'Type');
$table->setText(1, 1, display_select($filename));
$table->setText(2, 0, 'Output');
$table->setText(2, 1, display_output($output, $dpi));
$table->setText(3, 0, 'DPI');
$table->setText(3, 1, display_dpi($output, $dpi));
$table->setText(4, 0, 'Thickness');
$table->setText(4, 1, display_thickness($thickness));
$table->setText(5, 0, 'Resolution');
$table->setText(5, 1, display_res($res));
$table->setText(6, 0, 'Rotation');
$table->setText(6, 1, display_rotation($rotation));
$table->setText(7, 0, 'Font');
$table->setText(7, 1, display_font($font_family, $font_size));
$table->setText(8, 0, 'Text');
$table->setText(8, 1, display_text($text2display));
$table->addCellAttribute(9, 0, 'align', 'center');
$table->addCellAttribute(9, 0, 'colspan', '2');
$table->setText(9, 0, '<input type="submit" value="Generate" />');
if(!empty($text2display)) {
$table->insertRows(10, 1);
$table->addCellAttribute(10, 0, 'align', 'center');
$table->addCellAttribute(10, 0, 'colspan', '2');
$table->addRowAttribute(10, 'style','background-color: #ffffff');
$table->setText(10, 0, '<img src="image.php?code=' . $filename . '&amp;o=' . $output . '&amp;dpi=' . $dpi . '&amp;t=' . $thickness . '&amp;r=' . $res . '&amp;rot=' . $rotation . '&amp;text=' . urlencode($text2display) . '&amp;f1=' . $font_family . '&amp;f2=' . $font_size . '&amp;a1=' . $a1 . '&amp;a2=' . $a2 . '&amp;a3=' . $a3 . '" alt="Barcode Image" />');
}
?>

View File

@@ -0,0 +1,34 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 4);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, '<label for="checksum">Checksum</label>');
$text2display = '<input type="checkbox" name="a1" id="checksum" value="1"';
if($a1 == 1) {
$text2display .= ' checked="checked"';
}
$text2display .= ' />';
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' .$keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 2, 1, $text2display);
$table->setText($n + 3, 0, 'Explanation');
$table->setText($n + 3, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Interleaved 2 of 5 is based on Standard 2 of 5 symbology.</li><li>There is an optional checksum.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,57 @@
<?php
if(isset($_GET['code'], $_GET['t'], $_GET['r'], $_GET['rot'], $_GET['text'], $_GET['f1'], $_GET['f2'], $_GET['o'], $_GET['dpi'], $_GET['a1'], $_GET['a2'])) {
require('config.php');
require($class_dir . '/BCGColor.php');
require($class_dir . '/BCGBarcode.php');
require($class_dir . '/BCGDrawing.php');
require($class_dir . '/BCGFont.php');
if(include($class_dir . '/BCG' . $_GET['code'] . '.barcode.php')) {
if($_GET['f1'] !== '0' && $_GET['f1'] !== '-1' && intval($_GET['f2']) >= 1) {
$font = new BCGFont($class_dir . '/font/' . $_GET['f1'], intval($_GET['f2']));
} else {
$font = 0;
}
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);
$codebar = 'BCG' . $_GET['code'];
$code_generated = new $codebar();
if(isset($_GET['a1']) && intval($_GET['a1']) === 1) {
$code_generated->setChecksum(true);
}
if(isset($_GET['a2']) && !empty($_GET['a2'])) {
$code_generated->setStart($_GET['a2']);
}
if(isset($_GET['a3']) && !empty($_GET['a3'])) {
$code_generated->setLabel($_GET['a3']);
}
$code_generated->setThickness($_GET['t']);
$code_generated->setScale($_GET['r']);
$code_generated->setBackgroundColor($color_white);
$code_generated->setForegroundColor($color_black);
$code_generated->setFont($font);
$code_generated->parse($_GET['text']);
$drawing = new BCGDrawing('', $color_white);
$drawing->setBarcode($code_generated);
$drawing->setRotationAngle($_GET['rot']);
$drawing->setDPI($_GET['dpi'] == 'null' ? null : (int)$_GET['dpi']);
$drawing->draw();
if(intval($_GET['o']) === 1) {
header('Content-Type: image/png');
} elseif(intval($_GET['o']) === 2) {
header('Content-Type: image/jpeg');
} elseif(intval($_GET['o']) === 3) {
header('Content-Type: image/gif');
}
$drawing->finish(intval($_GET['o']));
}
else{
header('Content-Type: image/png');
readfile('error.png');
}
}
else{
header('Content-Type: image/png');
readfile('error.png');
}
?>

View File

@@ -0,0 +1,3 @@
<?php
header('Location: code39.php');
?>

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>ISBN stands for International Standard Book Number.</li><li>ISBN type is based on EAN-13.</li><li>Previously, all ISBN were in EAN-10 format. EAN-13 uses the same encoding but may contain different data in the ISBN number.</li><li>Composed by a GS1 prefix (for ISBN-13), a group identifier, a publisher code, an item number and a check digit.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,34 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 4);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, '<label for="checksum">Checksum</label>');
$text2display = '<input type="checkbox" name="a1" id="checksum" value="1"';
if($a1==1) {
$text2display .= ' checked="checked"';
}
$text2display .= ' />';
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 2, 1, $text2display);
$table->setText($n + 3, 0, 'Explanation');
$table->setText($n + 3, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Developed by the MSI Data Corporation.</li><li>Used primarily to mark retail shelves for inventory control.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,20 @@
<?php
define('IN_CB', true);
include('header.php');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Text Label');
$table->setText($n + 1, 1, '<input type="text" name="a3" value="' . $a3 . '" />');
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Enter width of each bars with one characters. Begin by a bar.</li><li>10523 : Will do 2px bar, 1px space, 6px bar, 3px space, 4px bar.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Used to encode enveloppe in USA.</li><li>You can provide<br />5 digits (ZIP Code)<br />9 digits (ZIP+4 code)<br />11 digits (ZIP+4 code+2 digits)<br />(Those 2 digits are taken from your address. If your address is 6453, the code will be 53.)</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,34 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 4);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0,'align', 'center');
$table->addCellAttribute($n, 0,'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, '<label for="checksum">Checksum</label>');
$text2display = '<input type="checkbox" name="a1" id="checksum" value="1"';
if($a1 == 1) {
$text2display .= ' checked="checked"';
}
$text2display .= ' />';
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 2, 1, $text2display);
$table->setText($n + 3, 0, 'Explanation');
$table->setText($n + 3, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Known also as Industrial 2 of 5.</li><li>Standard 2 of 5 is a low-density numeric symbology that has been with us since the 1960s.</li><li>There is an optional checksum.</li><li>Note : Standard 2 of 5 is REALLY tough to read !</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,17 @@
/***********************************************************
* style.css
* -----------------
* Created : Thr, Dec 11, 2003
* Copyright : (C) LookStrike Team
* WebSite : http://www.lookstrike.com
*
* $Id: style.css,v 1.1.1.1 2005/06/26 15:46:26 jsgoupil Exp $
*
***********************************************************/
TABLE { font: 12px Arial, Helvetica, sans-serif, Verdana; color: #000000; }
TH { font-weight: bold; font-size: 13px; color: #ffffff; height: 25px; background-color: #55598A; }
.tableline { border: #576bb9 1px solid; }
.table_title { background-color: #636799; }
.row1 { background-color: #B4B5DA; }
.row2 { background-color: #9FA1CA; }

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Encoded as EAN-13.</li><li>Most common and well-known in the USA.</li><li>There is 1 number system (NS), 5 manufacturer code, 5 product code and 1 check digit.</li><li>NS Description :<br />0 = Regular UPC Code<br />2 = Weight Items<br />3 = Drug/Health Items<br />4 = In-Store Use on Non-Food Items<br />5 = Coupons<br />7 = Regular UPC Code<br />And other are Reserved.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Short version of UPC symbol, 8 characters.</li><li>It is a conversion of an UPC-A for small package.</li><li>You can provide directly an UPC-A (11 chars) or UPC-E (6 chars) code.</li><li>UPC-E contain a system number and a check digit.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1,$text2display);
$table->setText($n + 2, 0,'Explanation');
$table->setText($n + 2, 1,'<ul style="margin: 0px; padding-left: 25px;"><li>Extension for UPC-A, UPC-E, EAN-13 and EAN-8.</li><li>Used for encode additional information for newspaper, books...</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,27 @@
<?php
define('IN_CB', true);
include('header.php');
$keys = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$n = $table->numRows();
$table->insertRows($n, 3);
$table->addRowAttribute($n, 'class', 'table_title');
$table->addCellAttribute($n, 0, 'align', 'center');
$table->addCellAttribute($n, 0, 'colspan', '2');
$table->setText($n, 0, '<font color="#ffffff"><b>Specifics Configs</b></font>');
$table->setText($n + 1, 0, 'Keys');
$text2display = '';
$c = count($keys);
for($i = 0; $i < $c; $i++) {
$text2display .= '<input type="button" value="' . $keys[$i] . '" style="width:25px;padding:0px;" onclick="newkey(this.form,\'' . $keys[$i] . '\')" /> ';
}
$table->setText($n + 1, 1, $text2display);
$table->setText($n + 2, 0, 'Explanation');
$table->setText($n + 2, 1, '<ul style="margin: 0px; padding-left: 25px;"><li>Extension for UPC-A, UPC-E, EAN-13 and EAN-8.</li><li>Used to encode suggested retail price.</li><li>If the first number is a 0, the price xx.xx is expressed in British Pounds. If it is a 5, it is expressed in US dollars.</li><li>Special Code Description :<br />90000 : No suggested retail price<br />99991 : The item is a complementary of another one. Normally free<br />99990 : Used bh National Association of College Stores to mark "used book".<br />90001 to 98999 : Internal purposes for some publishers.</li></ul>');
$table->draw();
echo '</form>';
include('footer.php');
?>

View File

@@ -0,0 +1,18 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="de">
<head>
<title>votian</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="votian"> <meta name="keywords" content="votian">
<meta http-equiv="refresh" content="0; URL=../index.php">
<link rel="stylesheet" type="text/css" href="css/phoenix.css">
</head>
<body bgcolor="#FFFFFA" leftmargin="1" topmargin="1" marginwidth="0" marginheight="0" link="#990000" vlink="#990000" alink="#990000">
<a href="../index.php">Bitte hier klicken, wenn Sie nicht automatisch weitergeleitet werden...</a>
</body>
</html>

View File

@@ -0,0 +1,3 @@
<?php
header('Location: html/code39.php');
?>

View File

@@ -0,0 +1,38 @@
<?php
// Including all required classes
require('class/BCGFont.php');
require('class/BCGColor.php');
require('class/BCGDrawing.php');
// Including the barcode technology
include('class/BCGcode39.barcode.php');
// Loading Font
$font =& new BCGFont('./class/font/Arial.ttf', 18);
// The arguments are R, G, B for color.
$color_black =& new BCGColor(0, 0, 0);
$color_white =& new BCGColor(255, 255, 255);
$code =& new BCGcode39();
$code->setScale(2); // Resolution
$code->setThickness(30); // Thickness
$code->setForegroundColor($color_black); // Color of bars
$code->setBackgroundColor($color_white); // Color of spaces
$code->setFont($font); // Font (or 0)
$code->parse('HELLO'); // Text
/* Here is the list of the arguments
1 - Filename (empty : display on screen)
2 - Background color */
$drawing =& new BCGDrawing('', $color_white);
$drawing->setBarcode($code);
$drawing->draw();
// Header that says it is an image (remove it if you save the barcode to a file)
header('Content-Type: image/png');
// Draw (or save) the image into PNG format.
$drawing->finish($drawing->IMG_FORMAT_PNG);
?>