here is the code i use. It resized the image proprtionally with the maximum width and height given., hope it helps you:
function thumbnail5($image_path,$thumb_path,$image_name,$thumb_width,$type)
{
$max_width = 100;
$max_height = 75;
if($type == 'gif'){
$src_img = imagecreatefromgif($image_path . $image_name);
}elseif($type == 'png'){
$src_img = imagecreatefrompng($image_path . $image_name);
}else{
$src_img = imagecreatefromjpeg($image_path . $image_name);
}
$size = getimagesize($image_path . $image_name); // Read the size
$width = $size[0];
$height = $size[1];
// Proportionally resize the image to the
// max sizes specified above
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if( ($width <= $max_width) && ($height <= $max_height) )
{
$tn_width = $width;
$tn_height = $height;
}
elseif (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$dst_img = imagecreatetruecolor($tn_width,$tn_height);
imagecopyresized($dst_img,$src_img,0,0,0,0,$tn_width,$tn_height,imagesx($src_img),imagesy($src_img));
#imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
if($type == 'gif'){
imagegif($dst_img, $thumb_path .$image_name);
}elseif($type == 'png'){
imagepng($dst_img, $thumb_path .$image_name);
}else{
imagejpeg($dst_img, $thumb_path .$image_name);
}
return true;
}