I guess the main reason for doing this would be to deal with images that have text in them which you probably want to convert to PNG rather than JPEG, right? If that's the case then how about feeding the image into some sort of OCR software to figure out if there is any recognizable text in there? I have no idea if that's practical or not, just an idea.