picqer / php-barcode-generator

Barcode generator in PHP that is easy to use, non-bloated and framework independent.
GNU Lesser General Public License v3.0
1.66k stars 400 forks source link

TYPE_EAN_13 Error with 13 numbers #180

Closed yakhyomus closed 1 year ago

yakhyomus commented 1 year ago

When i'm trying like this: $generator->getBarcode('478000000000', $generator::TYPE_EAN_13) with 12 numbers all is good, but when i'm trying with 13 numbers: $generator->getBarcode('4780000000000', $generator::TYPE_EAN_13) i got error:

Exception 'Picqer\Barcode\Exceptions\InvalidCheckDigitException' with message '' 

in /app/vendor/picqer/php-barcode-generator/src/Types/TypeEanUpcBase.php:47

Whats wrong? Can somebody help me pls? Thank yout!

JanMikes commented 1 year ago

Hi, it believe is because 4780000000000 is not valid EAN13 - the exception says it all InvalidCheckDigitException

Your 4780000000000 is not valid, check digit is 7, therefore 4780000000007 is valid EAN13.

You can calculate online for example on https://www.gs1.org/services/check-digit-calculator or use some formulas that can be found on internet.

casperbakker commented 1 year ago

Yep, JanMikes is right. It is not a valid EAN13 number. You can create a Code128 barcode if you really want 4780000000000 in the barcode. But it is not valid if you want EAN13.