Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/02/2010, 12:56
dj manvid
 
Fecha de Ingreso: febrero-2004
Ubicación: Puerto Rico
Mensajes: 12
Antigüedad: 20 años, 2 meses
Puntos: 0
Respuesta: Redimencionar una Imagen

Saludos!! Yo cree este código! espero que te funcione! hay la tengo a 90 de compresión!
Cita:

chmod($file,0644);
$max_upload_width = 1000;
$max_upload_height = 674;

list($image_width, $image_height) = getimagesize($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);

if($exts2 == "gif"){$image_source = imagecreatefromgif($file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagegif($new_image,$file,90);}
if($exts2 == "GIF"){$image_source = imagecreatefromgif($file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagegif($new_image,$file,90);}
if($exts2 == "jpg"){$image_source = imagecreatefromjpeg($file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$file,90);}
if($exts2 == "JPG"){$image_source = imagecreatefromjpeg($file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$file,90);}
if($exts2 == "jpeg"){$image_source = imagecreatefromjpeg($file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$file,90);}
if($exts2 == "JPEG"){$image_source = imagecreatefromjpeg($file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$file,90);}
if($exts2 == "png"){$image_source = imagecreatefrompng($file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagepng($new_image,$file,90);}
if($exts2 == "PNG"){$image_source = imagecreatefrompng($file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagepng($new_image,$file,90);}

imagedestroy($new_image);
}