You can carry out a basic file type check by looking at the extension, alternatively you can also check the actual contents within the file to make sure it is definitely a gif or jpeg (to prevent someone just renaming a .txt file to .gif) but an extension check should work for most intents and purposes.
The extension check, use explode:
$type=explode(".",$userfilename);
For type check:
$type = $_FILES['image']['type'];
Then run a selection statement to determine what type of image file has been uploaded, and which function you're going to use. (you can add in the other image formats yourself):
if (preg_match("/jpg|jpeg/",$type)){$srcimg=imagecreatefromjpeg($prod_img);}
if (preg_match("/png/",$type)){$srcimg=imagecreatefrompng($prod_img);}
Likewise at the end you need to use the same info to determine which function your gonna use to create the image:
if (preg_match("/png/",$type)){
imagepng($destimg,$prod_img_thumb);
} else {
imagejpeg($destimg,$prod_img_thumb);
Of course using and elseif or even a switch statement if you want to include gifs aswell.