improve logic for parsing a image extension