Ver Mensaje Individual
  #2 (permalink)  
Antiguo 20/08/2010, 16:28
Avatar de ebe
ebe
 
Fecha de Ingreso: marzo-2004
Ubicación: Guatemala
Mensajes: 363
Antigüedad: 20 años, 1 mes
Puntos: 11
Respuesta: Redimensionar imágenes de un directorio

Hola

con opendir() y readdir() puedes obtener el puntero del directorio y empezar a leer su contenido. Luego para redimensionar podrias usar algo como esto

Código PHP:
Ver original
  1. function resizeImage($file,$scale="",$width="",$height="")
  2.  {
  3.         // If they wish to scale the image.
  4.         if (isset($scale))
  5.         {
  6.                // Create our image object from the image.
  7.                $fullImage = imagecreatefromjpeg($file);
  8.                // Get the image size, used in calculations later.
  9.                $fullSize = getimagesize($file);
  10.                // If there is NOT a thumbnail for this image, make one.
  11.                if (!file_exists("tn_".$file))
  12.                {
  13.                       // Create our thumbnail size, so we can resize to this, and save it.
  14.                       $tnImage = imagecreatetruecolor($fullSize[0]/$scale, $fullSize[1]/$scale);
  15.                       // Resize the image.
  16.                       imagecopyresampled($tnImage,$fullImage,0,0,0,0,$fullSize[0]/$scale,$fullSize[1]/$scale,$fullSize[0],$fullSize[1]);
  17.                       // Create a new image thumbnail.
  18.                       imagejpeg($tnImage, "tn_".$file);
  19.                      
  20.                       // Clean Up.
  21.                       imagedestroy($fullImage);
  22.                       imagedestroy($tnImage);
  23.                       // Return our new image.
  24.                       return "tn_".$file;
  25.                }
  26.                // If there is a thumbnail file, lets just load it.  
  27.                else
  28.                       return "tn_".$file;
  29.         }
  30.         // If they want to force whatever size they want.
  31.         elseif (isset($width) && isset($height))
  32.         {
  33.                return "tn_".$file;
  34.         }
  35.         else
  36.         {
  37.                return false;
  38.         }
  39.  }


con GD activado.

saludos
__________________
http://dev.wsnetcorp.com