I need to crop an image so its exactly 309 x 175 pixels without stretching the image.
I can do a square but couldn’t figure out how to modify it:
[code=php]list($width, $height) = getimagesize($file) ;
$thumb_size = 100;
$size = getimagesize($file);
$width = $size[0];
$height = $size[1];
if($width > $height) {
$x = ceil(($width – $height) / 2 );
$y = 0;
$width = $height;
} elseif($height > $width) {
$y = ceil(($height – $width) / 2);
$x = 0;
$height = $width;
}
$tn = imagecreatetruecolor($thumb_size,$thumb_size);
$image = imagecreatefromjpeg($file);
imagecopyresampled($tn,$image,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
imagejpeg($tn,$save,100);
Also I tried doing it this way, but it would just stretch the image:
[code=php] list($width, $height) = getimagesize($file);
$origRatio = $width/$height;
$modwidth = 309;
$modheight = 175;
$tn = imagecreatetruecolor($modwidth, $modheight);
$image = imagecreatefromjpeg($file);
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
imagejpeg($tn, $save, 100) ;
There has got to be a way.. right??? ?