Which makes your code more or less as follows:
// Load the PNG file from disk into memory
$im2 = imagecreatefrompng($image)
$im2 resource, . png jpeg; . "" , ; . .
imagecopy() and more code here
header("Content-Type: image/jpeg");
jpg (.. http://host.com/image.jpg), . JPG PHP, . PHP , HTML , - stdout, echo, / <?php ?>.
// compress as a jpeg, and send to browser
imagejpeg($im2,'',50);
imagejpeg , jpg ( ) stdout ( ). null, ''. , 50, jpeg . 100 , 0 - .