Updated resizeImage method to look for valid file format in given filename and use that if available