Okey so i am writing a image upload where we want to force the images to be 795x440px. They can be rezised but they have to keep their aspect ratio so they can be cropped also.
The new images comes out in the right size, but the cropped image from original file has the wrong ratio, tried some diffrent ways but can’t get it right.
The image i am testing right now, original file
http://image.bayimg.com/jaiflaada.jpg
The result from cropping
http://image.bayimg.com/jaifmaada.jpg
How do i get this right, so the image always gets the best size and crops the rest?
list($width, $height) = getimagesize($save_dir);
$prop = (795 / $width);
$height = floor($height * $prop);
$new_image = imagecreatetruecolor(795, 440);
$bgColor = imagecolorallocate($new_image, 255,255,255) or die("Couldn't allocate color");
imagefill($new_image , 0,0 , $bgColor) or die("Couldnt fill with color");
imagecopyresampled($new_image,$source_image,0,0,0,0,795,440,795,$height);
imagejpeg($new_image,$new_directory,100);
I do it like that: