=1 to enable NOTE: You must have GD-1.8 or higher compiled into PHP in order to use PNG and JPEG. GIF images only work with GD-1.5 and lower. (http://www.boutell.com) ANOTHER NOTE: If you actually intend to print the barcodes and scan them with a scanner, I highly recommend choosing JPEG with a quality of 100. Most browsers can't seem to print a PNG without mangling it beyond recognition. USAGE EXAMPLES FOR ANY PLAIN OLD HTML DOCUMENT: ----------------------------------------------- */ /*=============================================================================*/ //----------------------------------------------------------------------------- // Startup code //----------------------------------------------------------------------------- if (!isset ($text)) $text = 1; if (empty ($quality)) $quality = 100; if (empty ($width)) $width = 160; if (empty ($height)) $height = 80; if (!empty ($format)) $format = strtoupper ($format); switch ($type) { default: $type = 1; case 1: Barcode39 ($barcode, $width, $height, $quality, $format, $text); break; } //----------------------------------------------------------------------------- // Generate a Code 3 of 9 barcode //----------------------------------------------------------------------------- function Barcode39 ($barcode, $width, $height, $quality, $format, $text) { switch ($format) { default: $format = "JPEG"; case "JPEG": header ("Content-type: image/jpeg"); break; case "PNG": header ("Content-type: image/png"); break; case "GIF": header ("Content-type: image/gif"); break; } $im = ImageCreate ($width, $height) or die ("Cannot Initialize new GD image stream"); $White = ImageColorAllocate ($im, 255, 255, 255); $Black = ImageColorAllocate ($im, 0, 0, 0); //ImageColorTransparent ($im, $White); ImageInterLace ($im, 1); $NarrowRatio = 20; $WideRatio = 55; $QuietRatio = 35; $nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio)); $Pixels = $width / $nChars; $NarrowBar = (int)(20 * $Pixels); $WideBar = (int)(55 * $Pixels); $QuietBar = (int)(35 * $Pixels); $ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2); if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0)) { ImageString ($im, 1, 0, 0, "Image is too small!", $Black); OutputImage ($im, $format, $quality); exit; } $CurrentBarX = (int)(($width - $ActualWidth) / 2); $Color = $White; $BarcodeFull = "*".strtoupper ($barcode)."*"; settype ($BarcodeFull, "string"); if ($text != 0) { $FontNum = 3; $FontHeight = ImageFontHeight ($FontNum); $FontWidth = ImageFontWidth ($FontNum); $CenterLoc = (int)(($width-1) / 2) - (int)(($FontWidth * strlen($BarcodeFull)) / 2); ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$BarcodeFull", $Black); } for ($i=0; $i