Código de Barras em PHP
Publicado por Guilherme Reschke 04/02/2008
[ Hits: 13.157 ]
Homepage: http://www.ee.pucrs.br/~reschke
Função para gerar código de barras. Simples de usar e código de fácil leitura.
function barcode($valor)
{
$code_txt = "";
$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;
}
}
//Desenho da barra
//Guarda inicial
$code_txt = $code_txt . "\n<img src=./imgs/p.gif width=".$fino." height=".$altura." border=0><img\nsrc=./imgs/b.gif width=".$fino." height=".$altura." border=0><img\nsrc=./imgs/p.gif width=".$fino." height=".$altura." border=0><img\nsrc=./imgs/b.gif width=".$fino." height=".$altura." border=0><img\n";
$texto = $valor ;
if(bcmod(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 ;
}
$code_txt = $code_txt . " src=./imgs/p.gif width=".$f1." height=".$altura." border=0><img\n";
if (substr($f,$i,1) == "0")
{
$f2 = $fino ;
}
else
{
$f2 = $largo ;
}
$code_txt = $code_txt . " src=./imgs/b.gif width=".$f2." height=".$altura." border=0><img\n";
}
}
// Draw guarda final
$code_txt = $code_txt . " src=./imgs/p.gif width=".$largo." height=".$altura." border=0><img\nsrc=./imgs/b.gif width=".$fino." height=".$altura." border=0><img\nsrc=./imgs/p.gif width=1 height=".$altura." border=0>\n";
return $code_txt;
} //Fim da função
function esquerda($entra,$comp)
{
return substr($entra,0,$comp);
}
function direita($entra,$comp)
{
return substr($entra,strlen($entra)-$comp,$comp);
}
Converte um texto em seu respectivo codigo binario
Cirurgia para acelerar o openSUSE em HD externo via USB
Void Server como Domain Control
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Como fazer a conversão binária e aplicar as restrições no Linux
Como quebrar a senha de um servidor Linux Debian
Como bloquear pendrive em uma rede Linux
Um autoinstall.yaml para Ubuntu com foco em quem vai fazer máquina virtual
Instalar GRUB sem archinstall no Arch Linux em UEFI Problemático









