here's a function i use on my gallery to get the image size:
function get_sizes($src_w, $src_h, $dst_w,$dst_h ){
//src_w ,src_h-- start width and height
//dst_w ,dst_h-- end width and height
//return array w=>new width h=>new height mlt => multiplier
//the function tries to shrink or enalrge src_w,h in such a way to best fit them into dst_w,h
//keeping x to y ratio unchanged
//dst_w or/and dst_h can be "*" in this means that we dont care about that dimension
//for example if dst_w="*" then we will try to resize by height not caring about width
//(but resizing width in such a way to keep the xy ratio)
//if both = "*" we dont resize at all.
#### Calculate multipliers
$mlt_w = $dst_w / $src_w;
$mlt_h = $dst_h / $src_h;
$mlt = $mlt_w < $mlt_h ? $mlt_w:$mlt_h;
if($dst_w == "*") $mlt = $mlt_h;
if($dst_h == "*") $mlt = $mlt_w;
if($dst_w == "*" && $dst_h == "*") $mlt=1;
#### Calculate new dimensions
$img_new_w = round($src_w * $mlt);
$img_new_h = round($src_h * $mlt);
return array("w" => $img_new_w, "h" => $img_new_h, "mlt_w"=>$mlt_w, "mlt_h"=>$mlt_h, "mlt"=>$mlt);
}