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

Generating wrong PNG in CODE_128 #121

Closed kakadong802 closed 3 years ago

kakadong802 commented 3 years ago

Here is my code :

`require 'vendor/autoload.php';

$generator = new Picqer\Barcode\BarcodeGeneratorPNG(); file_put_contents('barcode.png', $generator->getBarcode('20010211100000021B', $generator::TYPE_CODE_128));`

it generate this barcode:
barcode

However the correct one should look like this one : barcode (4)

Please Fix this error . Thanks a lot .

joeybab3 commented 3 years ago

The one generated does scan for the record

casperbakker commented 3 years ago

They are both correct. With Code 128 there are multiple ways to encode characters and to switch between A, B and C mode. It looks like the one from our library is more compact, probably because it has so many numbers and those can be encoded with 2 numbers together in 1 char, making the resulting barcode smaller. Because of the 'B' in the end we switch to a different mode for the last part, but the other barcode generator probably uses a single method that also supports the B.