Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/02/2013, 23:00
Avatar de erozwashere
erozwashere
 
Fecha de Ingreso: noviembre-2012
Ubicación: mex
Mensajes: 176
Antigüedad: 11 años, 6 meses
Puntos: 0
Cual es mi error en esta funcion? php

Hola tengo este codigo (lo copie de aqui mismo del foro)

para redimenccionar imagenes en php es decir crear thumbls

aqui el codigo

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

todo funciona correctamente, pero cuando pongo un if para comprobar el tamaño de la imagen que se subio,

es decir compruebo el tamaña y si el tamaño es mayor aplico la funcion.. aqui el codigo completo ..

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

me muestra este error

Fatal error: Call to undefined function redim() in A:\AppServ\www\reducir.php on line 64

y no se porque si todo parece estar prefecto, alguien que sepa ayuda !