here is the full code that is in production still. maybe this will help. cjoki
<?php
/*
This is a program to generate a code 128B barcode and returns an image.
Chris J, 2009-11-04
\*/
function gen\_code128($string, $fid, $size = 1, $height = 50, $show\_text = true)
{
// $string is string to convert to bar code
// $fid is the filename, it will default to the $string if no is provided
// $size is the pixel width of the bar code and is used as a base unit for each barcode/space
// based on the # of 0's or 1's in a row.
// for example the stop bar code hash is 11000111010. This is drawn as a bar 2 units wide, a space 3 units wide, a bar
// 3 units wide, a space 1 unit wide, a bar 1 unit wide followed by a space 1 unit wide. If the size is equal to 3 (for 3 pixels)
// this will mean the barcode for the stop is bar 6 pixels, space 9 pixels, bar 9 pixels, space 3 pixels, bar 3 pixels and space
// 3 pixels. The entire code will messure 33 pixels in width. of course that is just for the stop (the end of the code 128 barcode).
// $height is the height of the barcode in pixels. There must be room for for some padding on the top and bottom and room for
// the text of $string to be printed just under the barcode.
// at the front and back of a code 128 barcode is a blank space called the quiet zone. It should be 10 times the unit ($size in my function)
// the $show\_text parameter determines if a string will display under the barcode, this string will be the text version of the barcode.
include('hash\_code\_128.php');
$bcstring = '';
$cnt = strlen($string) ;
$quiet\_zone = 10\*$size-1;
$pad\_top = 5;
$pad\_bottom = 5;
$ttl\_width = ($quiet\_zone\*2)+($size\*($cnt+3)\*11)+2; // include string length + start + stop + checksum + front and back quiet zones
if($show\_text)
{
$pad\_text = 3;
$font\_size = 5;
$font\_left = $quiet\_zone;
$font\_top = $pad\_text + $height;
$ttl\_height = $pad\_top + $pad\_text + $font\_size + $pad\_bottom + $height;
}
else
{
$ttl\_height = $pad\_top + $pad\_bottom + $height;
}
$running\_checksum = 104; // START B hardcoded...
$bcstring.=$b\_enc\['104'\];
// build the barcode
for($i=0;$i<$cnt;$i++)
{
$position = $i+1;
$key = array\_search($string\[$i\],$b\_chr,true);
$bcstring.=$b\_enc\[$key\];
$running\_checksum+=($position\*$key);
// echo "<p>pos: ".$position."<br>char: ".$string\[$i\]."<br>key: ".$key."<br&g