Código de Barras em PHP
Publicado por Guilherme Reschke 04/02/2008
[ Hits: 12.943 ]
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); }
Aprenda a Gerenciar Permissões de Arquivos no Linux
Como transformar um áudio em vídeo com efeito de forma de onda (wave form)
Como aprovar Pull Requests em seu repositório Github via linha de comando
Quebra de linha na data e hora no Linux Mint
Organizando seus PDF com o Zotero
tentando instalar em um notebook antigo o Linux LegacyOS_2023... [RESO... (9)
Problema com Conexão Outlook via Firewall (OpenSUSE) com Internet Fibr... (5)