Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/01/2005, 09:36
xberni
 
Fecha de Ingreso: enero-2005
Ubicación: Barcelona (España)
Mensajes: 134
Antigüedad: 19 años, 3 meses
Puntos: 0
Te envío un par de funciones. La primera sólo "fuerza" la imagen a un width o height máximo. La segunda la reduce realmente, es decir, reemplaza la original por una copia con un width y height determinado.
Espero que te sirva.

function reduce_imagen($imagen, $max_width, $max_height) {

//if (!$max_width)
// $max_width = 100;
//if (!$max_height)
// $max_height = 80;


$size = GetImageSize($imagen);
$width = $size[0];
$height = $size[1];



//if ($width == 0)
//$width = 1;
//if ($height == 0)
//$height = 1;

$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;

global $tn_width, $tn_height;

if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}

return $tn_width; $tn_height;

}


function recorta_imagen($imagen, $max_width, $max_height) {

//if (!$max_width)
// $max_width = 100;
//if (!$max_height)
// $max_height = 80;


$size = GetImageSize($imagen);
$width = $size[0];
$height = $size[1];



//if ($width == 0)
//$width = 1;
//if ($height == 0)
//$height = 1;

$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;

if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}

$src = ImageCreateFromJpeg($imagen);
$dst = ImageCreateTrueColor($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,$tn_width,$tn_height,$width,$height);
header('Content-type: image/jpeg');
ImageJpeg($dst, $imagen, 100);
ImageDestroy($src);
ImageDestroy($dst);



}