Ver Mensaje Individual
  #4 (permalink)  
Antiguo 25/02/2015, 14:37
Avatar de witchy
witchy
 
Fecha de Ingreso: junio-2014
Mensajes: 44
Antigüedad: 9 años, 10 meses
Puntos: 0
Respuesta: Generar codigos de barra

Ahora tengo otro error cuando pongo alguna etiqueta hatml en la twig que genera el codigo no se muestra

Código HTML:
Ver original
  1. <p>el codigo</p>
  2. {{ bar_code(codenumber,'0','file.gif','190','130','true') }}

este es el metodo de la funcion

Código PHP:
Ver original
  1. public function barCode($codigo,$int,$filename,$ancho,$altura,$showcode)
  2.     {
  3.         $bs=new barCodeGenrator($codigo,$int,$filename,$ancho,$altura,$showcode);
  4.  
  5.        
  6.         return new Response(
  7.  
  8.            array(
  9.                 'Content-Type' => 'image/gif',
  10.  
  11.             )
  12.         );
  13.  
  14.     }

y esta es la clase que estoy usando
Código PHP:
Ver original
  1. <?php
  2.  
  3.  
  4. namespace Empresas\GestionBundle\Barcode;
  5.  
  6.  
  7. class barCodeGenrator {
  8.  
  9.     private $file;
  10.     private $into;
  11.     private $digitArray = array(0=>"00110",1=>"10001",2=>"01001",3=>"11000",4=>"00101",5=>"10100",6=>"01100",7=>"00011",8=>"10010",9=>"01010");
  12.     function __construct($value,$into=1, $filename = 'barcode.gif', $width_bar=300, $height_bar=65, $show_codebar=false) {
  13.  
  14.         $lower = 1 ; $hight = 50;
  15.         $this->into = $into;
  16.         $this->file = $filename;
  17.         for($count1=9;$count1>=0;$count1--){
  18.             for($count2=9;$count2>=0;$count2--){
  19.                 $count = ($count1 * 10) + $count2 ;
  20.                 $text = "" ;
  21.                 for($i=1;$i<6;$i++){
  22.                     $text .=  substr($this->digitArray[$count1],($i-1),1) . substr($this->digitArray[$count2],($i-1),1);
  23.                 }
  24.                 $this->digitArray[$count] = $text;
  25.             }
  26.         }
  27.  
  28.  
  29.         $height_bar_max = $height_bar;
  30.         $width_bar_max  = $width_bar;
  31.  
  32.         $img        = imagecreate($width_bar_max,$height_bar_max);
  33.         if ($show_codebar) {
  34.             $height_bar -= 25;
  35.         }
  36.  
  37.         $cl_black = imagecolorallocate($img, 0, 0, 0);
  38.         $cl_white = imagecolorallocate($img, 255, 255, 255);
  39.  
  40.         #imagefilledrectangle($img, 0, 0, $lower*95+1000, $hight+300, $cl_white);
  41.        imagefilledrectangle($img, 0, 0, $width_bar_max, $height_bar_max, $cl_white);
  42.         imagefilledrectangle($img, 5,5,5,$height_bar,$cl_black);
  43.         imagefilledrectangle($img, 6,5,6,$height_bar,$cl_white);
  44.         imagefilledrectangle($img, 7,5,7,$height_bar,$cl_black);
  45.         imagefilledrectangle($img, 8,5,8,$height_bar,$cl_white);
  46.         $thin = 1 ;
  47.         if(substr_count(strtoupper($_SERVER['SERVER_SOFTWARE']),"WIN32")){
  48.             $wide = 3;
  49.         } else {
  50.             $wide = 2.72;
  51.         }
  52.         $pos   = 9 ;
  53.         $text = $value ;
  54.         if((strlen($text) % 2) <> 0){
  55.             $text = "0" . $text;
  56.         }
  57.  
  58.  
  59.         while (strlen($text) > 0) {
  60.             $i = round($this->JSK_left($text,2));
  61.             $text = $this->JSK_right($text,strlen($text)-2);
  62.  
  63.             $f = $this->digitArray[$i];
  64.  
  65.             for($i=1;$i<11;$i+=2){
  66.                 if (substr($f,($i-1),1) == "0") {
  67.                     $f1 = $thin ;
  68.                 }else{
  69.                     $f1 = $wide ;
  70.                 }
  71.                 imagefilledrectangle($img, $pos,5,$pos-1+$f1,$height_bar,$cl_black)  ;
  72.                 $pos = $pos + $f1 ;
  73.  
  74.                 if (substr($f,$i,1) == "0") {
  75.                     $f2 = $thin ;
  76.                 }else{
  77.                     $f2 = $wide ;
  78.                 }
  79.                 imagefilledrectangle($img, $pos,5,$pos-1+$f2,$height_bar,$cl_white)  ;
  80.                 $pos = $pos + $f2 ;
  81.             }
  82.         }
  83.         imagefilledrectangle($img, $pos,5,$pos-1+$wide,$height_bar,$cl_black);
  84.         $pos=$pos+$wide;
  85.  
  86.         imagefilledrectangle($img, $pos,5,$pos-1+$thin,$height_bar,$cl_white);
  87.         $pos=$pos+$thin;
  88.  
  89.  
  90.         imagefilledrectangle($img, $pos,5,$pos-1+$thin,$height_bar,$cl_black);
  91.         $pos=$pos+$thin;
  92.  
  93.         if ($show_codebar) {
  94.             imagestring($img, 5, 0, $height_bar+5, " ".$value, imagecolorallocate($img, 0, 0, 0));
  95.         }
  96.  
  97.         $this->put_img($img);
  98.     }
  99.  
  100.     function JSK_left($input,$comp){
  101.         return substr($input,0,$comp);
  102.     }
  103.  
  104.     function JSK_right($input,$comp){
  105.         return substr($input,strlen($input)-$comp,$comp);
  106.     }
  107.     function put_img($image,$file='test.gif'){
  108.         if($this->into){
  109.             imagegif($image,$this->file);
  110.         } else {
  111.             header("Content-type: image/gif");
  112.             imagegif($image);
  113.         }
  114.         imagedestroy($image);
  115.     }
  116.  
  117. }

Muchas Graciasss y saludos