Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/04/2010, 09:07
Avatar de gogupe
gogupe
 
Fecha de Ingreso: octubre-2006
Ubicación: Mallorca
Mensajes: 897
Antigüedad: 20 años
Puntos: 32
Respuesta: Usar libreria gd para redimensionar imagenes.

Usa este script, a mi me funciona perfectamente,
modifica los valores $max_upload_width ó $max_upload_height para hacerlo a tu gusto, yo lo tengo que la foto, en este caso un avatar, me salga 200x200.

Código PHP:
<?
$max_upload_width 
= 200;
$max_upload_height = 200;

$remote_file = "../fotografias/".$_FILES["imagen"]["name"];  //la ruta donde se encuentra la imagen
                                    
imagejpeg($image_source,$remote_file,100);
chmod($remote_file,0777);


list(
$image_width, $image_height) = getimagesize($remote_file);
                                        
if(
$image_width>$max_upload_width || $image_height >$max_upload_height)
    {
        
$proportions = $image_width/$image_height;

        if(
$image_width>$image_height){
            
$new_width = $max_upload_width;
            
$new_height = round($max_upload_width/$proportions);
        }
        else{
            
$new_height = $max_upload_height;
            
$new_width = round($max_upload_height*$proportions);
        }

        
$new_image = imagecreatetruecolor($new_width , $new_height);
        
$image_source = imagecreatefromjpeg($remote_file);

        
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
        
imagejpeg($new_image,$remote_file,100);

        
imagedestroy($new_image);
    }

imagedestroy($image_source);
?>
Saludos