Ir para conteúdo
Fórum Script Brasil
  • 0

Código de barras


pm79

Pergunta

Boa tarde a todos

Estou com um problema ao colocar uma função php que gera o codigo de barras dentro do html

se colocar a função apenas dentro de um ficheiro ela funciona e gera a imagem com o codigo de barras, mas se colocar demtro do html não

Assim funciona

<?

function CodigoBarras($code) {

$lw = 2; $hi = 100;

$Lencode = array('0001101','0011001','0010011','0111101','0100011',

'0110001','0101111','0111011','0110111','0001011');

$Rencode = array('1110010','1100110','1101100','1000010','1011100',

'1001110','1010000','1000100','1001000','1110100');

$ends = '101'; $center = '01010';

/* UPC-A Must be 11 digits, we compute the checksum. */

if ( strlen($code) != 11 ) { die("O codigo tem que conter 11 digitos."); }

/* Compute the EAN-13 Checksum digit */

$ncode = '0'.$code;

$even = 0; $odd = 0;

for ($x=0;$x<12;$x++) {

if ($x % 2) { $odd += $ncode[$x]; } else { $even += $ncode[$x]; }

}

$code.=(10 - (($odd * 3 + $even) % 10)) % 10;

/* Create the bar encoding using a binary string */

$bars=$ends;

$bars.=$Lencode[$code[0]];

for($x=1;$x<6;$x++) {

$bars.=$Lencode[$code[$x]];

}

$bars.=$center;

for($x=6;$x<12;$x++) {

$bars.=$Rencode[$code[$x]];

}

$bars.=$ends;

/* Generate the Barcode Image */

$img = ImageCreate($lw*95+30,$hi+30);

$fg = ImageColorAllocate($img, 0, 0, 0);

$bg = ImageColorAllocate($img, 255, 255, 255);

ImageFilledRectangle($img, 0, 0, $lw*95+30, $hi+30, $bg);

$shift=10;

for ($x=0;$x<strlen($bars);$x++) {

if (($x<10) || ($x>=45 && $x<50) || ($x >=85)) { $sh=10; } else { $sh=0; }

if ($bars[$x] == '1') { $color = $fg; } else { $color = $bg; }

ImageFilledRectangle($img, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);

}

/* Add the Human Readable Label */

ImageString($img,4,5,$hi-5,$code[0],$fg);

for ($x=0;$x<5;$x++) {

ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);

ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg);

}

ImageString($img,4,$lw*95+17,$hi-5,$code[11],$fg);

/* Output the Header and Content. */

header("Content-Type: image/png");

ImagePNG($img);

}

CodigoBarras("12345678910");

?>

Assim não funciona

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Documento sin t&iacute;tulo</title>

<style type="text/css">

<!--

body,td,th {

color: #000000;

font-family: Arial, Helvetica, sans-serif;

}

body {

background-color: #FFFFFF;

margin-left: 0px;

margin-top: 0px;

margin-right: 0px;

margin-bottom: 0px;

}

a:link {

text-decoration: none;

}

a:visited {

text-decoration: none;

}

a:hover {

text-decoration: none;

}

a:active {

text-decoration: none;

}

.Estilo1 {

color: #FFFFFF;

font-weight: bold;

}

.Estilo3 {font-size: 12px}

-->

</style></head>

<body>

<table width="575" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td colspan="3" bgcolor="#0099FF"><div align="center"><span class="Estilo1">Clínica Assemblydesign</span></div></td>

</tr>

<tr>

<td width="242" height="1"><span class="Estilo3">Nome</span></td>

<td width="7" rowspan="5">&nbsp;</td>

<td width="326">

<label></label> <?php echo $nome ?></td>

</tr>

<tr>

<td width="242" height="0">Exame</td>

<td><label><?php echo $exame ?></label></td>

</tr>

<tr>

<td width="242">Estado</td>

<td><?php echo $estado ?></td>

</tr>

<tr>

<td width="242" height="8">Data</td>

<td><?php echo $data ?></td>

</tr>

<tr>

<td width="242" height="17">Número de controlo</td>

<td> <?php

function CodigoBarras($code) {

$lw = 2; $hi = 100;

$Lencode = array('0001101','0011001','0010011','0111101','0100011',

'0110001','0101111','0111011','0110111','0001011');

$Rencode = array('1110010','1100110','1101100','1000010','1011100',

'1001110','1010000','1000100','1001000','1110100');

$ends = '101'; $center = '01010';

/* UPC-A Must be 11 digits, we compute the checksum. */

if ( strlen($code) != 11 ) { die("O codigo tem que conter 11 digitos."); }

/* Compute the EAN-13 Checksum digit */

$ncode = '0'.$code;

$even = 0; $odd = 0;

for ($x=0;$x<12;$x++) {

if ($x % 2) { $odd += $ncode[$x]; } else { $even += $ncode[$x]; }

}

$code.=(10 - (($odd * 3 + $even) % 10)) % 10;

/* Create the bar encoding using a binary string */

$bars=$ends;

$bars.=$Lencode[$code[0]];

for($x=1;$x<6;$x++) {

$bars.=$Lencode[$code[$x]];

}

$bars.=$center;

for($x=6;$x<12;$x++) {

$bars.=$Rencode[$code[$x]];

}

$bars.=$ends;

/* Generate the Barcode Image */

$img = ImageCreate($lw*95+30,$hi+30);

$fg = ImageColorAllocate($img, 0, 0, 0);

$bg = ImageColorAllocate($img, 255, 255, 255);

ImageFilledRectangle($img, 0, 0, $lw*95+30, $hi+30, $bg);

$shift=10;

for ($x=0;$x<strlen($bars);$x++) {

if (($x<10) || ($x>=45 && $x<50) || ($x >=85)) { $sh=10; } else { $sh=0; }

if ($bars[$x] == '1') { $color = $fg; } else { $color = $bg; }

ImageFilledRectangle($img, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);

}

/* Add the Human Readable Label */

ImageString($img,4,5,$hi-5,$code[0],$fg);

for ($x=0;$x<5;$x++) {

ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);

ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg);

}

ImageString($img,4,$lw*95+17,$hi-5,$code[11],$fg);

/* Output the Header and Content. */

header("Content-Type: image/png");

ImagePNG($img);

}

CodigoBarras("12345678910");

?> </td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td><label></label></td>

</tr>

</table>

</body>

</html>

Será que podem ajudar para itegrar isto dentro do html?

Obrigado a todos os que possam ajudar

Pedro

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0
se for o caso dessa Função funcionar separada. deixe ela fora desse html. use um INCLUDE(); chamando essa função.

^^

Já testei gravar apenas a função num ficheiro chamado barra.php e depois ai chamei esse ficheiro com a função usando o include, mas infelizmente não funcionou.

Seria essa a sua ideia?

Obrigado pela ajuda

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...