Dysan Posted November 7, 2007 Share Posted November 7, 2007 I have the following code, that carries out the following in order to create a barcode on the fly. But for some strange reason, the barcodes doesn't scan once printed. Why is this? - How else are Code 39 Barcodes encoded? Basically, the code converts an ASCII string into a Binary string. The code then searches the Binary string and upon finding a 0 outputs a white bar (rectangle), and a black bar upon finding a 1. <?php $rectangle_width = 2; $rectangle_height = 20; $image = imagecreatetruecolor(500, 182); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); imagefill($image, 0, 0, $white); $find = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*'); $replace = array('00110000', '00110001', '00110010', '00110011', '00110100', '00110101', '00110110', '00110111', '00111000', '00111001', '00101010'); $string = '*1101*'; $textstring = str_replace($find, $replace, $string); $j = 0; $sarray = str_split($textstring, 1); for($i = 0; $i < count($sarray); $i++) { if($sarray[$i] == '0') { imagefilledrectangle($image, $rectangle_width * $j, 0, ($rectangle_width * $j) + $rectangle_width, $rectangle_height, $white); $j++; } elseif($sarray[$i] == '1') { imagefilledrectangle($image, $rectangle_width * $j, 0, ($rectangle_width * $j) + $rectangle_width, $rectangle_height, $black); $j++; } } header("Content-type: image/jpeg"); imagejpeg($image); imagedestroy($image); ?> Quote Link to comment Share on other sites More sharing options...
Daukan Posted November 7, 2007 Share Posted November 7, 2007 Works for me. I just tried it on server. Quote Link to comment Share on other sites More sharing options...
Dysan Posted November 7, 2007 Author Share Posted November 7, 2007 Yes it works on computer, but the barcode scanner doesn't scan it once printed. Why is this? Quote Link to comment Share on other sites More sharing options...
revraz Posted November 7, 2007 Share Posted November 7, 2007 May have to ask the Barcode Reader company. Quote Link to comment Share on other sites More sharing options...
Dysan Posted November 7, 2007 Author Share Posted November 7, 2007 What you think it looks OK? How come if you change the string *1101* to * the barcode for the * isn't the same as shown on the picture here: http://www.codeproject.com/bitmap/barcode1.asp?df=100&forumid=4090&exp=0&select=1905375 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.