This will resize your image but it won't stretch it and it'll keep right proportions. Basically this crops your image to fit the best.
function createThumb($source,$dest) {
$thumb_size = 230; // square thumbs
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];
// you might comment this to make regular thumbs and add a thumb width var. keep this for square thumbs
if($width> $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} else if ($height> $width) {
$y = ceil(($height - $width) / 2);
$height = $width;
}
$new_im = ImageCreatetruecolor($thumb_size,$thumb_size);
$im = imagecreatefromjpeg($source);
imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
imagejpeg($new_im,$dest,100);
}
0 comentarios:
Publicar un comentario