I have seen code on manipulating graphic images from local files, but not on saving graphic in gif or jpeg format.

I will be having pictures upload to the site I am working on and want to create small thumbnails for users to pick. Would it be best to just create the thumbnails as needed from the larger jpeg files, or generate and save them on the upload. If the later, how do you save in the compressed graphic format?