Spectroscopic determination of the magnetic-field distribution in an imploding plasma