when you call imageimage_format/i you need to supply the second parameter: file-name. Once you do that, you'll have an image that you can use.
// Save in same folder
imagegif($im, 'my_image.gif');
// Save in images folder
imagejpg($im, $_SERVER['DOCUMENT_ROOT'].'/images/my_image.gif');