It should be relatively easy to do some naive checking to separate a JPEG from a PNG. According to Wikipedia, JPEG files always start with FF D8
. PNGs however seem to start with 89 50
, so one can easily distinguish between the two from just reading a byte or two from the file.
I would recommend looking up the file formats of the most important image types just to make sure there isn't some other mainstream one starting with FF D8
. It seems unlikely however.
Edit: JPEG, PNG, GIF, BMP and TIFF all seem to have magic values at the start of the files to tell them apart form other types.