Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.3

Bug #13794 Some numbers produce malformed "UPC A" barcodes
Submitted: 2008-04-28 20:12 UTC
From: sframe Assigned: doconnor
Status: Closed Package: Image_Barcode (version 1.1.0)
PHP Version: 5.2.4 OS: "OS 10.4.11" and "Ubuntu 8.04"
Roadmaps: 1.1.1    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 20 + 22 = ?

 
 [2008-04-28 20:12 UTC] sframe (Shawn Frame)
Description: ------------ This fellow's website produces UPC A codes correctly: http://jkbworld.com/doc/imagebarcode-upca.php When I try to use this number 764262044911 for UPC A I get a malformed barcode that will not scan. 764262044911 generated by GNUBarcode, will scan correctly. Test script: --------------- <?php require_once("Image/Barcode.php"); $num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '764262044911'; $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : 'upca'; $imgtype = isset($_REQUEST['imgtype']) ? $_REQUEST['imgtype'] : 'png'; Image_Barcode::draw($num, $type, $imgtype); ?> Expected result: ---------------- Produce a scannable image Actual result: -------------- Left half of barcode appears to be malformed. Right half of barcode appears to be correct.

Comments

 [2008-05-03 06:32 UTC] doconnor (Daniel O'Connor)
Hey Shawn, are you able to post an example of the generated (incorrect) image?
 [2008-05-03 06:37 UTC] doconnor (Daniel O'Connor)
Cleaner test case: <?php require_once "Image/Barcode.php"; ob_start(); Image_Barcode::draw('764262044911', 'upca', 'png'); $png = ob_get_clean(); file_put_contents(dirname(__FILE__) . "/bug-13794.png", $png);
 [2008-05-03 06:40 UTC] doconnor (Daniel O'Connor)
I get http://www.flickr.com/photos/clockwerx/2460387109/ when I run the test script. Windows, PHP 5.2.6, Image_Barcode-1.1.0
 [2008-05-05 15:03 UTC] sframe (Shawn Frame)
Hi Daniel, I Posted a side-by-side comparison of the two barcodes. One made with Gnu Barcode (scans correctly) and the other Image_Barcode (not scannable). http://www.flickr.com/photos/26301979@N03/2468125952/ I don't know if the above image will scan at all, but it should show the differences between the barcodes themselves. Fantastic script. I am very hopeful that a solution will arise.
 [2008-09-06 18:50 UTC] martinco (Martin Collins)
Hi, Firstly, I'd like to thank you for writing this. I too came accross this bug, and i believe (having tested a few hundred checks) the following patch should sort it and cut down a few lines :) --- upca.php.orig Sat Sep 06 18:57:19 2008 +++ upca.php Sat Sep 06 19:42:22 2008 @@ -135,21 +135,6 @@ ); - var $_number_set_left_coding = array( - '0' => array('A','A','A','A','A','A'), - '1' => array('A','A','B','A','B','B'), - '2' => array('A','A','B','B','A','B'), - '3' => array('A','A','B','B','B','A'), - '4' => array('A','B','A','A','B','B'), - '5' => array('A','B','B','A','A','B'), - '6' => array('A','B','B','B','A','A'), - '7' => array('A','B','A','B','A','B'), - '8' => array('A','B','A','B','B','A'), - '9' => array('A','B','B','A','B','A') - ); - - - /** * Draws a UPC-A image barcode * @@ -231,11 +216,8 @@ imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); $xpos += $this->_barwidth; - $set_array = $this->_number_set_left_coding[$key]; - - - foreach ($this->_number_set['0'][$set_array[0]] as $bar) { + foreach ($this->_number_set[$key]['A'] as $bar) { if ($bar) { imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $barcodelongheight, $black); } @@ -251,7 +233,7 @@ //foreach ($this->_number_set[$value][$set_array[$idx-1]] as $bar) { - foreach ($this->_number_set[$value][$set_array[$idx]] as $bar) { + foreach ($this->_number_set[$value]['A'] as $bar) { if ($bar) { imagefilledrectangle($img, $xpos, 0, $xpos + $this->_barwidth - 1, $this->_barcodeheight, $black); }
 [2010-01-23 03:27 UTC] adrian_m (Adrian Mugica)
I added a patch, based mostly on the one martinco (Martin Collins) posted here in comments, with some additional cleanup of extra unneeded code.
 [2010-01-25 21:58 UTC] cweiske (Christian Weiske)
I can confirm that the attached patch a) looks good and b) makes the test script generate the same output as gnubarcode, just as shown on the flickr photo.
 [2010-02-14 07:49 UTC] doconnor (Daniel O'Connor)
-Status: Open +Status: Closed -Assigned To: +Assigned To: doconnor
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.