php-barcode-generator icon indicating copy to clipboard operation
php-barcode-generator copied to clipboard

UPC-E encoding completely wrong information

Open samymassoud opened this issue 4 years ago • 7 comments

Was trying to generate the UPC-E for the following number 12345687

The output image of the library as follows:

https://devtools360.com/en/barcode/generator

Which will read as 01891113 on the scanner While the correct one is:

https://devtools360.com/en/barcode/generator

Something with the conversion to UPC-A and back to UPC-E must be wrong!

BTW: This nice library is part of the Online barcode generator , so thanks for the great effort.

samymassoud avatar Dec 25 '20 13:12 samymassoud

Hi Samy,

Could you provide the code you use to generate the barcode?

Note that UPC-E is only valid with 6-digits. It will add a zero in front and a checksum in the end to create a valid UPC-E barcode. If you provide 8 digits, it will try to create an EAN-8 code as it is almost the same structure but valid with 8 digits.

If you have arbitrary lengths, then don't use UPC-E but the general purpose Code128

casperbakker avatar Dec 27 '20 14:12 casperbakker

Hi Casper,

When I try 6 digits barcode it is not readable on any software scanner.

Here is an example.

123456 Barcode

Other alternatives will not allow less than 7 digits for the UPC-E

So tried the same, but still can't be scanned!

0123456 Same code on another alternative which can be scanned correctly!

other alternative same code

samymassoud avatar Dec 29 '20 08:12 samymassoud

Please provide the code you use to generate the barcode with this library, otherwise I have no place to start testing.

casperbakker avatar Dec 29 '20 09:12 casperbakker

Sure

$generator = new BarcodeGeneratorPNG();
$color = [0,0,0];
$code = "0123456";
$img_str = $generator->getBarcode($code, $generator::TYPE_UPC_E,2, 90, $color);
echo '<img src="data:image/png;base64,' . base64_encode($img_str). '">';

samymassoud avatar Dec 29 '20 10:12 samymassoud

Has there been any movement or solutions on this. I am finding increasing numbers of UPC_E barcodes out in the wild and we currently are unable to create scannable barcodes for them.

Here is what we are currently doing. Note that I am currently hardcoding the 6 digit upc in. It is a real upc for Mountain Dew that is 01213405 and we are hardcoding in 121340 to be processed by the barcode generator and spit out a UPC_E. `

    $value = "01213405";
    if (strlen($value) == 8) {
        $value = substr($value, 1, 6);
        $height = 72;
        // hardcoding upc string for now
        $svgData = $generator->getBarcode("121340", $generator::TYPE_UPC_E, 2, $height);
    }

` This creates a barcode represented by this image: Screenshot from 2021-07-19 11-42-58 This appears to be a UPC style barcode given that it has the 4 different sized bars but is not scannable by barcode apps and does not look like like the barcode that exists for that given 6 digit code, represented by this image which was gotten by putting in "0121340" into this website. This is the correct barcode and matches the one on the side of the actual packaging. Screenshot from 2021-07-19 11-43-20 Trying to code it using EAN_8 does create a scannable barcode, but the barcode does not have the correct check value at the end (it creates it with a 9 for the check value). Passing the full 8 digit barcode using an EAN_8 type gives a "InvalidCheckDigitException" likely because for an EAN_8 to encode properly, it needs to be a 9.

We are currently running this in version 2.0.0

oitowl7 avatar Jul 19 '21 16:07 oitowl7

I figured out that the implemented UPC-E barcode is only working with UPC-A codes as input (properly converting them into UPC-E), but not with proper UPC-E codes as input. I started working on a solution for this issue.

Bernhard-Krop avatar Jul 01 '22 12:07 Bernhard-Krop

@casperbakker , @samymassoud , @oitowl7

I've provided a pull request for this issue. Once merged into the main branch, it should fix all your problems. Please, let me know if you have still problems with barcode type UPC-E.

Bernhard-Krop avatar Jul 04 '22 09:07 Bernhard-Krop