Change a png to a jpg


<?php
// Create a new image in the memory from the file 
$png_image = imagecreatefrompng( "input.png" );

// Save the image as output.jpg
imagejpeg( $png_image, "output.jpg" );

// Clear the memory of the temporary image 
imagedestroy( $png_image );
?>

Any transparency is lost in this case as jpg does not support transparency.
You can change from different formats by changing the imagecreatefrompng and the imagejpeg functions.