Ver Mensaje Individual
  #2 (permalink)  
Antiguo 12/09/2009, 10:54
Avatar de SergeMedina
SergeMedina
 
Fecha de Ingreso: septiembre-2007
Ubicación: Guadalajara, Jalisco
Mensajes: 459
Antigüedad: 19 años, 1 mes
Puntos: 20
Respuesta: cambiar nombre y redimensionar imagen.

Yo hice una función para ajustar una imagen a una "caja" de ancho $maxW y alto $maxH:
Código PHP:
/**
 *
 * @param int $maxW
 * @param int $maxH
 * @param string $imgUrl
 * @param int $multiploH
 * @return image/jpg
 */
function resizeImage($maxW, $maxH, $imgUrl, $multiploH=18){
    
$im=getimagesize($imgUrl);
    if(!
$im){//error
      
trigger_error("$imgUrl no es una imagen valida", E_USER_WARNING);
      return 
false;
    }
    
$imW=$im[0];
    
$imH=$im[1];
    
$Imp=$imW/$imH;
    
//echo "imW $imW maxW $maxW imH $imH maxH $maxH";
    
if($imW<=$maxW && $imH<=$maxH){
      
$newH=$imH;
      
$newW=$imW;
    } else if(
$imW>$imH && ($imW>$maxW || $imH > $maxH)){//Ancho mayor a alto
      
$newW=$maxW;
      
$newH=1/($Imp/$newW);
    } else if(
$imW<$imH && ($imW>$maxW || $imH > $maxH)){//Alto mayor a ancho
      
$newH=$maxH;
      
$newW=$newH*$Imp;
    } else if(
$imW==$imH){//imagen cuadrada
      
if($imW>$maxW){//imagen mayor a lo requerido
          
$newW=$maxW;
          
$newH=$maxW;
      }else{
          
$newH=$maxH;
          
$newW=$maxH;
      }
    }
    if(
is_numeric($multiploH)&&$multiploH>0){
        
$newH = floor($newH/$multiploH)*$multiploH;
        
$newW=$newH*$Imp;
    }
    switch(
$im[2]){
        case 
IMAGETYPE_JPEG:
            
$img = imagecreatefromjpeg($imgUrl);
            break;
        case 
IMAGETYPE_GIF:
            
$img = imagecreatefromgif($imgUrl);
            break;
        case 
IMAGETYPE_PNG:
            
$img = imagecreatefrompng($imgUrl);
            break;
    }
    
$thumb = imagecreatetruecolor($newW, $newH);
    
imagecopyresampled($thumb, $img, 0, 0, 0, 0, $newW, $newH, $imW, $imH);
    
header("Content-type: image/jpeg");
    
imagejpeg($thumb);
    
imagedestroy($thumb);
    
imagedestroy($img);
} 
__________________
I see dead pixels