Open listedegarde opened 5 years ago
Hi!
~I wonder if this is running as Code_128C or not.~
I know that those NEED to have even digits and zero is appended with the following code, for the Bar to be generated. This checks the length for MOD 2 (even number) and append the zero. What I find weird is that your example has already even number of digits.
// add trailling zero if odd digits on Code128C
$bc_string = strlen($bc_string) % 2 == 0 && $encoding === 'CODE_128_C'?
$bc_string : '0'.$bc_string;
If it is not here, then it is inside the Barcode generator code.
Yes, the problem was here, fix below
~Can you please run it in verbose mode and post the output here? The zero is appended AFTER the value is printed, but may still help anyways. Testing with different string would also help (eg. 012345 12345 1234 etc). Just to see if the behavior is different.~
I will make some testes here now.
Gus
Ok, I think I found the problem. Fix is published here https://github.com/tavinus/cli-barcode/commit/dce7413e3ea1791b2cf0df2df95e30417dfb8755
I would use git though:
git clone https://github.com/tavinus/cli-barcode.git
cd cli-barcode
./barcode.php --create-bash
sudo make install
If already used git, it is easy to update with
(also no need to reinstall)
# run this inside the cli-barcode folder
git pull
Make sure you have the new version (1.0.8
)
$ ./barcode --version
PHP-CLI Barcode v1.0.8
Please let me know if all went fine. Thanks for posting the problem! Gus
BTW, This is meant for CLI (terminal, bash, etc)
If you are really using from PHP,
You should just use https://github.com/picqer/php-barcode-generator
and then you would also not need to run with exec or anything.
You can use my script as an example on how to implement your code.
But he also has examples and a good readme there.
If you want to make a script that runs with predefined parameters,
I recommend wrapping with a Bash script (instead of PHP).
Cheers!
Gus
All the codes I create are always prepended by a zero. For example, if I use the code 123456 then the scanned code is 0123456. Here is the exact code I am using to generate the barcode:
<?php exec('barcode -h 90 -e CODE_128 -f PNG "123456" bcode.png'); ?>
Here is the code I used to install:
1) cd /usr/local/bin/ 2) wget https://github.com/tavinus/cli-barcode/archive/master.tar.gz 3) tar -zxvf master.tar.gz 4) cd cli-barcode-master/ 5) ./barcode.php --create-bash 6) sudo make install