from my understanding, OP's question is more about calculating new dimensions, rather than resizing
@Psyche, this is actually a simple arithmetic issue. Suppose you have an 640x480 image and want to show it in a 200x200 "box".
$sw = 640; $sh = 480;
$dw = 200; $dh = 200;
find out the aspect ratio of the box, compare it with that of original and calculate either width of height for the new image
$sr = $sw / $sh;
$dr = $dw / $dh;
if($sr > $dr)
$dh = round($dw / $sr);
else
$dw = round($dh * $sr);
this gives you 200x150 and this is the size to which you need to scale the original image