Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra 0 prepended to barcode #2

Open
listedegarde opened this issue Nov 19, 2018 · 3 comments
Open

Extra 0 prepended to barcode #2

listedegarde opened this issue Nov 19, 2018 · 3 comments

Comments

@listedegarde
Copy link

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
@tavinus
Copy link
Owner

tavinus commented Nov 20, 2018

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

@tavinus
Copy link
Owner

tavinus commented Nov 20, 2018

Ok, I think I found the problem. Fix is published here dce7413

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

@tavinus tavinus self-assigned this Nov 20, 2018
tavinus referenced this issue Nov 20, 2018
Fix trailing zero when not CODE_128_C
@tavinus
Copy link
Owner

tavinus commented Nov 20, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants