Foros del Web » Programando para Internet » PHP » Symfony »

Generar codigos de barra

Estas en el tema de Generar codigos de barra en el foro de Symfony en Foros del Web. Hola, estoy tratado de generar codigos de barra, necesito que sea automatico, estoy probando un ejemplo que encontre para php barcode-generator-2012-04-06.zip http://www.phpclasses.org/browse/pac...nload/zip.html solo funciona bien ...
  #1 (permalink)  
Antiguo 23/02/2015, 16:19
Avatar de witchy  
Fecha de Ingreso: junio-2014
Mensajes: 44
Antigüedad: 9 años, 10 meses
Puntos: 0
Generar codigos de barra

Hola, estoy tratado de generar codigos de barra, necesito que sea automatico, estoy probando un ejemplo que encontre para php
barcode-generator-2012-04-06.zip http://www.phpclasses.org/browse/pac...nload/zip.html solo funciona bien pero cuando lo agrego con symfony llego hasta aqui.

Cree la clase barCodeGenrator en mi bundle le puse el namepace y la agregue a mi controladora en la cual puse esta funcion y me quede ahi porque no se me ocurre mas nada y el error que me da cuando corro es que la variable que estoy devolviendo no es un string
Código PHP:
Ver original
  1. /**
  2.      *
  3.      * @Route("/numerobarra" , name="boletas_numerobarra")
  4.      * @Template()
  5.      */
  6.     public function numerobarraAction()
  7.     {
  8.  
  9.  
  10.         $code_number = '125689365472365458';
  11.         #new barCodeGenrator($code_number,0,'hello.gif');
  12.        $barcode = new barCodeGenrator($code_number,0,'hello.gif', 190, 130, true);
  13.  
  14.         return array(
  15.             'barcode' => $barcode,
  16.         );
  17.  
  18.     }

De verdad necesito ayuda.....muchas graciass
  #2 (permalink)  
Antiguo 24/02/2015, 15:41
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 10 meses
Puntos: 379
Respuesta: Generar codigos de barra

Creo que el error es muy simple, si imprimes con un var_dump te darás cuenta por que $bacode no es string
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.
  #3 (permalink)  
Antiguo 25/02/2015, 09:54
Avatar de witchy  
Fecha de Ingreso: junio-2014
Mensajes: 44
Antigüedad: 9 años, 10 meses
Puntos: 0
Respuesta: Generar codigos de barra

Hola, graciasss bueno eso era uno de lo errores, ya lo solucione haciendo una funcion para twig que ejecutara la clase que me generaba la imagen de los codigos...Saludos y Graciass
  #4 (permalink)  
Antiguo 25/02/2015, 14:37
Avatar de 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

Etiquetas: barra, codigos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:23.