-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarra.php
More file actions
93 lines (80 loc) · 2.33 KB
/
barra.php
File metadata and controls
93 lines (80 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
$valor = $_POST['valor'];
if($valor == ""){
$valor = isset($valor) ? $valor : "34191183400000292011090000107160253"; // Valor Inicial
}
fbarcode($valor); // basta chamar essa função com o valor do código para gerar o código de barras
function fbarcode($valor){
$fino = 1 ;
$largo = 3 ;
$altura = 40 ;
$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;
}
}
//Desenho da barra
//Guarda inicial
?>
<img src="p.gif" width="<?php echo $fino; ?>" height="<?php echo $altura; ?>" border="0">
<img src="b.gif" width="<?php echo $fino; ?>" height="<?php echo $altura; ?>" border="0">
<img src="p.gif" width="<?php echo $fino; ?>" height="<?php echo $altura; ?>" border="0">
<img src="b.gif" width="<?php echo $fino; ?>" height="<?php echo $altura; ?>" border="0">
<?php
$texto = $valor ;
if((strlen($texto) % 2) <> 0){
$texto = "0" . $texto;
}
// Draw dos dados
while (strlen($texto) > 0) {
$i = round(esquerda($texto,2));
$texto = direita($texto,strlen($texto)-2);
$f = $barcodes[$i];
for($i=1;$i<11;$i+=2){
if (substr($f,($i-1),1) == "0") {
$f1 = $fino ;
}else{
$f1 = $largo ;
}
?>
<img src="p.gif" width="<?php echo $f1; ?>" height="<?php echo $altura; ?>" border="0">
<?php
if (substr($f,$i,1) == "0") {
$f2 = $fino ;
}else{
$f2 = $largo ;
}
?>
<img src="b.gif" width="<?php echo $f2; ?>" height="<?php echo $altura; ?>" border="0">
<?php
}
}
// Draw guarda final
?>
<img src="p.gif" width="<?php echo $largo; ?>" height="<?php echo $altura; ?>" border="0">
<img src="b.gif" width="<?php echo $fino; ?>" height="<?php echo $altura; ?>" border="0">
<img src="p.gif" width="<?php echo 1; ?>" height="<?php echo $altura; ?>" border="0">
<?php
} //Fim da função
function esquerda($entra,$comp){
return substr($entra,0,$comp);
}
function direita($entra,$comp){
return substr($entra,strlen($entra)-$comp,$comp);
}
?>