Voltar para Paste Lymas | pasteLog v. 2.0-alpha

Visualizando código



Postado por Anônimo em 02/07/2009 22:49:36.
http://paste.lymas.com.br/510

Clique AQUI para fazer download do código. Esconder número da linha

  1. <?php
  2. /*
  3. Autor: Sidiney Sodré Gali de Souza <sidsodre@bol.com.br>
  4. Data: 21/11/2005
  5.  
  6. Código de Barras - código-fonte   em:
  7. http://www.vivaolinux.com.br/scripts/verFonte.php?codigo=1394
  8. */
  9.  
  10. function CodigoBarras($code) {
  11.   $lw = 2; $hi = 100;
  12.   $Lencode = array('0001101','0011001','0010011','0111101','0100011',
  13.                    '0110001','0101111','0111011','0110111','0001011');
  14.   $Rencode = array('1110010','1100110','1101100','1000010','1011100',
  15.                    '1001110','1010000','1000100','1001000','1110100');
  16.   $ends = '101'; $center = '01010';
  17.   /* UPC-A Must be 11 digits, we compute the checksum. */
  18.   if ( strlen($code) != 11 ) { die("UPC-A Must be 11 digits."); }
  19.   /* Compute the EAN-13 Checksum digit */
  20.   $ncode = '0'.$code;
  21.   $even = 0; $odd = 0;
  22.   for ($x=0;$x<12;$x++) {
  23.    if ($x % 2) { $odd += $ncode[$x]; } else { $even += $ncode[$x]; }
  24.   }
  25.   $code.=(10 - (($odd * 3 + $even) % 10)) % 10;
  26.   /* Create the bar encoding using a binary string */
  27.   $bars=$ends;
  28.   $bars.=$Lencode[$code[0]];
  29.   for($x=1;$x<6;$x++) {
  30.    $bars.=$Lencode[$code[$x]];
  31.   }
  32.   $bars.=$center;
  33.   for($x=6;$x<12;$x++) {
  34.    $bars.=$Rencode[$code[$x]];
  35.   }
  36.   $bars.=$ends;
  37.   /* Generate the Barcode Image */
  38.   $img = ImageCreate($lw*95+30,$hi+30);
  39.   $fg = ImageColorAllocate($img, 0, 0, 0);
  40.   $bg = ImageColorAllocate($img, 255, 255, 255);
  41.   ImageFilledRectangle($img, 0, 0, $lw*95+30, $hi+30, $bg);
  42.   $shift=10;
  43.   for ($x=0;$x<strlen($bars);$x++) {
  44.    if (($x<10) || ($x>=45 && $x<50) || ($x >=85)) { $sh=10; } else { $sh=0; }
  45.    if ($bars[$x] == '1') { $color = $fg; } else { $color = $bg; }
  46.    ImageFilledRectangle($img, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);
  47.   }
  48.   /* Add the Human Readable Label */
  49.   ImageString($img,4,5,$hi-5,$code[0],$fg);
  50.   for ($x=0;$x<5;$x++) {
  51.    ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);
  52.    ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg);
  53.   }
  54.   ImageString($img,4,$lw*95+17,$hi-5,$code[11],$fg);
  55.   /* Output the Header and Content. */
  56.   header("Content-Type: image/png");
  57.   ImagePNG($img);
  58. }
  59.  
  60. CodigoBarras('54879874586');
  61. ?>  
  62.  


Colando um novo código


Seu Apelido:
Guardar o apelido em um cookie?

Linguagem:


Código: