
Codigo Barra PHP
Publicado por German Alvarenga (5 intervenciones) el 11/04/2013 15:49:54
Buenas Comunidad de Programadores tengo una pequena duda estoy haciendo un programa que me genere codigo de barra y queria saber si me podrian ayudar es que no me sale.
les agradeceria su ayuda porfavor.
luego tengo este codigo
les agradeceria su ayuda porfavor.
1
2
3
4
5
6
7
8
9
10
11
12
<html lang="en">
<head>
<title><!-- Insert your title here --></title>
</head>
<body>
<form action="codigo_barras2.php" method="post">
Ingrese el Codigo:
<input name="numero" type="text" />
<input type="submit" value="Enviar" />
</form>
</body>
</html>
luego tengo este codigo
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
<html lang="en">
<head>
<title><!-- Insert your title here --></title>
</head>
<body>
<?php
$altura = 40;
$cod = $_POST['numero'];
function tamano($numero,$altura)
{
$cifras = strlen($numero) + 1;
$dim['x'] = 7 + $cifras*6 + 9;
$dim['y'] = $altura + 1;
return $dim;
}
$dimensiones = tamano($cod,$altura);
$imagen = imagecreate($dimensiones['x'], $dimensiones['y']);
$blanco = imagecolorallocate($imagen,255,255,255);
$negro = imagecolorallocate($imagen,0,0,0);
imagefill($imagen, 0, 0, $blanco);
imagerectangle($imagen, 0, 0, imageSX($imagen) - 1, imageSY($imagen) - 1, $negro);
function cifra($num)
{
return str_pad(decbin($num + 5), 4, '0', STR_PAD_LEFT);
}
function barra($y2, $x_ini, $codigo)
{
global $imagen, $negro, $blanco;
for($i = 0; $i <=3; $i++)
{
if($codigo[$i] == 0)
{
$color = $blanco;
}else{
$color = $negro;
}
$x = $x_ini + $i;
imageline($imagen, $x, 5, $x, $y2, $color);
}
}
function codigo($numero)
{
global $imagen, $negro, $blanco, $altura;
$x = 5;
barra($altura - 5, $x, "1010");
$x = $x + 7;
for($e = 0; $e<=strlen($numero) - 1; $e++)
{
barra($altura - 15, $x, cifra($numero[$e]));
imagestring($imagen, 2, $x, $altura - 15, $numero[$e], $negro);
$x = $x + 6;
}
$x = $x + 1;
barra($altura - 5, $x, "1011");
}
codigo($cod, $altura);
header("Content-type: image/png");
imagepng($imagen);
?>
</body>
</html>
Valora esta pregunta


0