Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/01/2008, 15:50
nompalidece
 
Fecha de Ingreso: febrero-2006
Mensajes: 10
Antigüedad: 18 años, 2 meses
Puntos: 1
Re: Redimensionar imagen a altura y ancho fijos SIN deformar

Cita:
Iniciado por Italico76 Ver Mensaje
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$image0000$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$image0000$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....