1
First:
I’m using the function below and am implementing a chile.
Reason: need to generate several codes, example: 1 2 3 4 5 .... 98 99 100,follows code:
<?php
$i = 1;
while ($i <= 100) {
function geraCodigoBarra($numero){
$fino = 1;
$largo = 3;
$altura = 70;
$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" />';
echo'<br>';
echo'<br>';
echo"EAN: $i";
}
geraCodigoBarra('$i');
echo $i++;
}
?>
Return:
EAN: 111 Fatal error: Cannot redeclare geraCodigoBarra() (Previously declared in C: xampp htdocs cb index.php:10) in C: xampp htdocs cb index.php on line 10
Second: After generating these codes, it is possible to export them separately to . jpg ? to a given folder? , if yes how could I do.
Finally:
I need the code to be 13 numbers,: 1
in 0000000000001
Where does $numero come from?
– Sr. André Baill
Since you are using PHP, perhaps it would be better to use the GD library and make the bars in one image. It’s out of the question, but the bar algorithm 2 of 5 can be simplified as well.
– Bacco
It would be good not to mix several doubts of a different nature in the same question. Usually it is more effective to ask separately, solving one problem at a time and moving on to the next in another post. This makes it easier for respondents, allows different people with specific knowledge to take better care of each subject, and decreases the chance of amplitude closure.
– Bacco