I got this code from a thread here in PHPBuilder, but it isn't working quite as it should. I want it to resize the image to the max width OR height specified. But if I want a picture to be max 300 wide OR 300 heigh, it converts the picture til 400x300.
/********************************************************************
Resizing images
********************************************************************/
function resizeimage($input_file, $output_file, $thumb_max_width, $thumb_max_height, $thumb_quality) {
// read image size
$size = getimagesize($input_file);
// read the input file
$input_image = imagecreatefromjpeg($input_file);
// compute ratio
$ratio = min($thumb_max_width,$size[0],$thumb_max_height/$size[1]);
// create output image
$output_image = ImageCreatefromjpeg($input_file);
// resample image
// when using GD 1.x change this to imagecopyresized
$output_image = imagecreatetruecolor(round($size[0] * $ratio),round($size[1] * $ratio));
imagecopyresampled($output_image, $input_image, 0, 0, 0, 0, round($size[0]* $ratio), round($size[1] * $ratio), $size[0], $size[1]);
// create output image
imagejpeg $output_image,$output_file,$thumb_quality);
imagedestroy($input_image);
imagedestroy($output_image);
}