Cita:
Iniciado por Italico76
Parece una contradiccion: ajustar el ancho y el alto de una imagen (fijar ambos dos parametros) y NO deformar pero lo he visto en muchas galerias de imagenes XXX.
He pensado un algoritmo para hacer eso pero necesito de una funcion del tipo de imagecopyresized que me permita elegir de la imagen origen LAS CUATRO coordenadas (x1,y1) y (x2,y2) y no solamente (x1,y1) como es esa funcion.
¿ Alguien sabe de algo asi ? no se me ocurre otra forma de poder hacer eso........
Ideas ?

Espero que esto te sirva:
Código PHP:
<?
$im = $_GET['im'];
$maxsize = $_GET['maxsize'];
if (strpos($im,"gif")==false){
if ($maxsize == '') {
$maxsize = 100;
}
// The file
$filename = $im;
// Set a maximum height and width
$width = $maxsize;
$height = $maxsize;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p);
imagedestroy($image);
imageDestroy($image_p);
}
//------------------------------------------------------------------ gif
else
{
if ($maxsize == '') {
$maxsize = 100;
}
// The file
$filename = $im;
// Set a maximum height and width
$width = $maxsize;
$height = $maxsize;
// Content type
Header("Content-type: image/gif");
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromgif($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imageGif($image_p);
imagedestroy($image);
imageDestroy($image_p);
$fuente = @imagecreatefromgif($im);
}
?>
Para visualizar la imagen tenes que usar lo siguiente:
Código PHP:
<img src="http://tupagina.com/thumbnail.php?im=./img/mi_image.jpg&maxsize=124">
Si queres agregarle mas extensiones deberias hacer un IFELSE para PNG por ejemplo. El script soporte solo JPG y GIFs
Saludos....