I have the following code that I use to resize some images on my server to a smaller size:
// get the ratio of the original image
list($orgwidth, $orgheight) = getimagesize($originalImageDir);
// create a thumb and source image to be resized
$thumb = imagecreatetruecolor($width, $height);
$source = imagecreatefromjpeg($originalImageDir);
// resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, round($height / $ratio), $height, $orgwidth, $thumbheight);
// save new thumb with quality 75
imagejpeg($thumb, $path, 75);
I am running into the following problem: I give my function a height and width of 300 and 200 respectively. Now, the original images are not that ratio, so I would like to be able to resize the original to a maximum width of 200 or a max height of 300; whichever one is the larger value.
So for example, if I have a 1200h x 1000w image, I want to resize it to a height of 240px and 200px, because in this case 200px was my maximum allowed width. And if I had an image that is 480h x 300w my new image would be resized to 300px height and 187px width because 300px is my maximum height and this brings me below the maximum allowed width.
Hope I am making sense. Anyway, if any php and math wizards have something cooked up, please do share 🙂
Thanks!
why not look at something like http://pear.php.net/package/Image_Transform/ that has various drivers for different image libraries and has just the functionality you are looking for?