Como puedo cabiar el tamaño si que afecte la calidad de la imagen. Algunas veces la cambia de color medio rojizo otras azules, y no se porque, . Manejo imagenes .JPG y utilizo un servicio de hosting que tiene compilado todas las librerias GD jpg, gif, png. y no entiendo porque. Utilizo este script para cambiar el tamaño de las imagenes:
Código PHP:
<?php
$image = $HTTP_GET_VARS['image']; //nombre de la imagen
$type = $HTTP_GET_VARS['type']; // para el tamaño de la figura, pues las
//utilizo para distintos cambios de tamaño.
switch($type)
{ case 1: if (!$max_width) $max_width = 250;
if (!$max_height) $max_height = 230;
break;
case 2: if (!$max_width) $max_width = 200;
if (!$max_height) $max_height = 180;
break;
case 3: if (!$max_width) $max_width = 200;
if (!$max_height) $max_height = 180;
break;
}
$size = GetImageSize($image);
$width = $size[0];
$height = $size[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($image);
if (!$src) { /* Comprobar si ha fallado */
$src = imagecreate (150, 30); /* Crear una imagen en blanco */
$bgc = imagecolorallocate ($src, 255, 255, 255);
$tc = imagecolorallocate ($src, 0, 0, 0);
imagefilledrectangle ($src, 0, 0, 150, 30, $bgc);
/* Mostrar un mensaje de error */
imagestring ($src, 1, 5, 5, "Error cargando $nombreimg", $tc);
}
$dst = ImageCreate($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,$tn_width,$tn_height,$width,$height);
header('Content-type: image/jpeg');
$r = imagejpeg($dst, null, -1);
ImageDestroy($src);
ImageDestroy($dst);
?>
Si alguien tiene alguna sugerencia para este problemilla, se los agradecere de antemano. .
Saludos,
Gildus