Error generating barcode in PHP

0

Well, my problem is this:

I have the line and I want to convert it to barcode.

You should be thinking, "This is very simple using some ready-made classes you have on the web!".

Well, I've tested several models and reading the generated bar code is interpreted with other numbers. At first it stays the same, but in certain parts of the code it changes, but I have no idea why.

Who can help me, I would be very grateful. I need a lot to solve this problem.

EXAMPLE:

Digitable line for conversion:

  

846100000005919402962014711150030007003147180834

What you are generating:

  

846100000005591940296203147111500301007003147183

<?php
function geraCodigoBarra($numero){
    $fino = 1;
    $largo = 3;
    $altura = 50;

    $barcodes[0] = '00110';
    $barcodes[1] = '10001';
    $barcodes[2] = '01001';
    $barcodes[3] = '11000';
    $barcodes[4] = '00101';
    $barcodes[5] = '10100';
    $barcodes[6] = '01100';
    $barcodes[7] = '00011';
    $barcodes[8] = '10010';
    $barcodes[9] = '01010';

    for($f1 = 9; $f1 >= 0; $f1--){
        for($f2 = 9; $f2 >= 0; $f2--){
            $f = ($f1*10)+$f2;
            $texto = '';
            for($i = 1; $i < 6; $i++){
                $texto .= substr($barcodes[$f1], ($i-1), 1).substr($barcodes[$f2] ,($i-1), 1);
            }
            $barcodes[$f] = $texto;
        }
    }

    echo '<img src="imagens/p.gif" width="'.$fino.'" height="'.$altura.'" border="0" />';
    echo '<img src="imagens/b.gif" width="'.$fino.'" height="'.$altura.'" border="0" />';
    echo '<img src="imagens/p.gif" width="'.$fino.'" height="'.$altura.'" border="0" />';
    echo '<img src="imagens/b.gif" width="'.$fino.'" height="'.$altura.'" border="0" />';

    echo '<img ';

    $texto = $numero;

    if((strlen($texto) % 2) <> 0){
        $texto = '0'.$texto;
    }

    while(strlen($texto) > 0){
        $i = round(substr($texto, 0, 2));
        $texto = substr($texto, strlen($texto)-(strlen($texto)-2), (strlen($texto)-2));

        if(isset($barcodes[$i])){
            $f = $barcodes[$i];
        }

        for($i = 1; $i < 11; $i+=2){
            if(substr($f, ($i-1), 1) == '0'){
                $f1 = $fino ;
            }else{
                $f1 = $largo ;
            }

            echo 'src="imagens/p.gif" width="'.$f1.'" height="'.$altura.'" border="0">';
            echo '<img ';

            if(substr($f, $i, 1) == '0'){
                $f2 = $fino ;
            }else{
                $f2 = $largo ;
            }

            echo 'src="imagens/b.gif" width="'.$f2.'" height="'.$altura.'" border="0">';
            echo '<img ';
        }
    }
    echo 'src="imagens/p.gif" width="'.$largo.'" height="'.$altura.'" border="0" />';
    echo '<img src="imagens/b.gif" width="'.$fino.'" height="'.$altura.'" border="0" />';
    echo '<img src="imagens/p.gif" width="1" height="'.$altura.'" border="0" />';
}

geraCodigoBarra('846100000005919402962014711150030007003147180834');
?>
    
asked by anonymous 01.11.2017 / 01:36

0 answers