Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/03/2012, 07:21
carolina3
 
Fecha de Ingreso: agosto-2011
Ubicación: barcelona
Mensajes: 237
Antigüedad: 12 años, 9 meses
Puntos: 1
re dimensionar imagen

hola

Estoy intentando re dimensionar una imagen y encontré este scrip en el foro pero al copiarlo parece ser que tiene un error en la escritura eso creo ya que me muestra una linea del código en negrita y no entiendo esa linea alguien sabría cual es el problema gracias de antemano

la linea es la 14: redim ($imagen,$imagen_final,$ancho_nuevo,$alto_nuevo);

Código PHP:
Ver original
  1. <?php
  2. ## CONFIGURACION #############################
  3.  
  4.     # ruta de la imagen a redimensionar
  5.    $imagen='imagen.jpg';
  6.     # ruta de la imagen final, si se pone el mismo nombre que la imagen, esta se sobreescribe
  7.    $imagen_final='imagen2.jpg';
  8.     $ancho_nuevo=90;
  9.     $alto_nuevo=55;
  10.  
  11. ## FIN CONFIGURACION #############################
  12.  
  13.  
  14. redim ($imagen,$imagen_final,$ancho_nuevo,$alto_nuevo);
  15.  
  16.  
  17. function redim($ruta1,$ruta2,$ancho,$alto)
  18.     {
  19.     # se obtene la dimension y tipo de imagen
  20.    $datos=getimagesize ($ruta1);
  21.      
  22.     $ancho_orig = $datos[0]; # Anchura de la imagen original
  23.    $alto_orig = $datos[1];    # Altura de la imagen original
  24.    $tipo = $datos[2];
  25.      
  26.     if ($tipo==1){ # GIF
  27.        if (function_exists("imagecreatefromgif"))
  28.             $img = imagecreatefromgif($ruta1);
  29.         else
  30.             return false;
  31.     }
  32.     else if ($tipo==2){ # JPG
  33.        if (function_exists("imagecreatefromjpeg"))
  34.             $img = imagecreatefromjpeg($ruta1);
  35.         else
  36.             return false;
  37.     }
  38.     else if ($tipo==3){ # PNG
  39.        if (function_exists("imagecreatefrompng"))
  40.             $img = imagecreatefrompng($ruta1);
  41.         else
  42.             return false;
  43.     }
  44.      
  45.     # Se calculan las nuevas dimensiones de la imagen
  46.    if ($ancho_orig>$alto_orig)
  47.         {
  48.         $ancho_dest=$ancho;
  49.         $alto_dest=($ancho_dest/$ancho_orig)*$alto_orig;
  50.         }
  51.     else
  52.         {
  53.         $alto_dest=$alto;
  54.         $ancho_dest=($alto_dest/$alto_orig)*$ancho_orig;
  55.         }
  56.  
  57.     // imagecreatetruecolor, solo estan en G.D. 2.0.1 con PHP 4.0.6+
  58.     $img2=@imagecreatetruecolor($ancho_dest,$alto_dest) or $img2=imagecreate($ancho_dest,$alto_dest);
  59.  
  60.     // Redimensionar
  61.     // imagecopyresampled, solo estan en G.D. 2.0.1 con PHP 4.0.6+
  62.     @imagecopyresampled($img2,$img,0,0,0,0,$ancho_dest,$alto_dest,$ancho_orig,$alto_orig) or imagecopyresized($img2,$img,0,0,0,0,$ancho_dest,$alto_dest,$ancho_orig,$alto_orig);
  63.  
  64.     // Crear fichero nuevo, según extensión.
  65.     if ($tipo==1) // GIF
  66.         if (function_exists("imagegif"))
  67.             imagegif($img2, $ruta2);
  68.         else
  69.             return false;
  70.  
  71.     if ($tipo==2) // JPG
  72.         if (function_exists("imagejpeg"))
  73.             imagejpeg($img2, $ruta2);
  74.         else
  75.             return false;
  76.  
  77.     if ($tipo==3)  // PNG
  78.         if (function_exists("imagepng"))
  79.             imagepng($img2, $ruta2);
  80.         else
  81.             return false;
  82.      
  83.     return true;
  84.     }
  85. ?>

me gustaría adaptar el código amis necesidades pero esta linea me tiene parada