Added more image formats and made the image format detection more robust.