Esta es la función:
Código PHP:
<?php
function resizeFit($im,$width,$height) {
//Original sizes
$ow = imagesx($im); $oh = imagesy($im);
//To fit the image in the new box by cropping data from the image, i have to check the biggest prop. in height and width
if($width/$ow > $height/$oh) {
$nw = $width;
$nh = ($oh * $nw) / $ow;
$px = 0;
$py = ($height - $nh) / 2;
} else {
$nh = $height;
$nw = ($ow * $nh) / $oh;
$py = 0;
$px = ($width - $nw) / 2;
}
//Create a new image width requested size
$new = imagecreatetruecolor($width,$height);
//Copy the image loosing the least space
imagecopyresampled($new, $im, $px, $py, 0, 0, $nw, $nh, $ow, $oh);
return $new;
}
?>
Código PHP:
$im = imagecreatefromjpeg($destino);
$resized = resizeFit($im, 100, 150);
imagepng($im,'curri/imagen.png');
Un saludo