I recently was looking to do the same thing. I started out trying to use the gd libs and got it working but it was kinda bloated and buggy. I opted to use imagemagick server side and it works great. Here's the function I wrote (assuming you're on a *nix box w/ access to imagemagick)
function createthumb($oldName,$newName,$new_w,$new_h){
exec("/usr/local/nf/bin/convert -size ".$new_w."x".$new_h." ".$oldName." " .$newName);
}
You will, of course, have to alter the path to imagemagick's convert command.
It works perfectly and isn't buggy. GD doesn't support .gif files, imagemagick does 🙂.