If you're using the script to print the image, you may want to try sending the image/jpeg header like this:
<?
header("Content-type: image/jpeg");
imagejpeg($im);
imageDestroy($im);
?>
make sure you're not printing/echoing anything above this. So to view the image, you would just call your script in the browser.
And if you want to print out the image using html like <img src="blah.jpg">, use something like this:
<?
Header("Content-type: image/jpeg");
ImageJPEG($im, 'filename.jpg');
ImageJPEG($im,'',20);
ImageDestroy($im);
echo "<img src=\"filename.jpg\">";
?>