pass the below function an open image in $im (ImageCreateFrom___) and where to draw in $x, $y, then the first digit on the bar code in $barcode_type, then the 5 digit company & item code. the check digit is calculated automatically.
i've successfully scanned bar codes created using this function then printed or faxed then scanned using cheap scanners (the cuecat works for example).
i haven't really tested this function (it works for what i'm doing with UPC A?) and i created it in an hour or two using some "how do barcodes work" web pages for kids so i'm just warning you that i'm not really sure what i'm doing. i haven't done much work with barcodes and i'm sure there are better ways to do this. =) there are commercial scripts for this, check out: http://www.tec-it.co.at/Common/Demo/Playground.asp?LN=1 or search on yahoo
as always, if you use this script credit is always appreciated. =)
function BarCode2Image($im, $x, $y, $barcode_type, $company_code, $item_code)
{
/ Bar Code Unit Lengths /
$BarCode_Array = array (
"0" => array ("3", "2", "1", "1"),
"1" => array ("2", "2", "2", "1"),
"2" => array ("2", "1", "2", "2"),
"3" => array ("1", "4", "1", "1"),
"4" => array ("1", "1", "3", "2"),
"5" => array ("1", "2", "3", "1"),
"6" => array ("1", "1", "1", "4"),
"7" => array ("1", "3", "1", "2"),
"8" => array ("1", "2", "1", "3"),
"9" => array ("3", "1", "1", "2"),
"s" => array ("1", "1", "1"),
"d" => array ("1", "1", "1", "1", "1")
);
$BarCode_Height = 20; #height of bar codes
$BarCode_Unit_Size = 1; #width of bar codes
$BarCode_Start = "s";
$BarCode_Stop = "s";
$BarCode_Divider = "d";
if (!$im)
Image_Error("No Image Opened For BarCode2Image");
$BarCode = $barcode_type.$company_code.$item_code;
$Check_Digit = (($BarCode[0] + $BarCode[2] + $BarCode[4] + $BarCode[6] + $BarCode[8] + $BarCode[10]) * 3) + ($BarCode[1] + $BarCode[3] + $BarCode[5] + $BarCode[7] + $BarCode[9]);
$Check_Digit = ((10 - ($Check_Digit % 10)) % 10);
$BarCode = $BarCode_Start.$barcode_type.$company_code.$BarCode_Divider.$item_code.$Check_Digit.$BarCode_Stop;
if(strlen($BarCode) != 15)
Image_Error("Invalid Bar Code Length! (Must Be 12 Digits Long)");
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
for($i = 0; $i < 15; $i++)
{
while($BarCode_Unit = each($BarCode_Array[$BarCode[$i]]))
{
if(($pos++ % 2) == 0)
ImageFilledRectangle($im, $x, $y, $x + ($BarCode_Unit[1] $BarCode_Unit_Size) - 1, $y+$BarCode_Height, $black);
else
ImageFilledRectangle($im, $x, $y, $x + ($BarCode_Unit[1] $BarCode_Unit_Size) - 1, $y+$BarCode_Height, $white);
$x = $x + ($BarCode_Unit[1] * $BarCode_Unit_Size);
}
reset($BarCode_Array);
reset($BarCode_Array[$BarCode[$i]]);
}
}