  The mass composition of cosmic rays contains important clues about their
origin. Accurate measurements are needed to resolve long-standing issues such
as the transition from Galactic to extragalactic origin, and the nature of the
cutoff observed at the highest energies. Composition can be studied by
measuring the atmospheric depth of the shower maximum Xmax of air showers
generated by high-energy cosmic rays hitting the Earth's atmosphere. We present
a new method to reconstruct Xmax based on radio measurements. The radio
emission mechanism of air showers is a complex process that creates an
asymmetric intensity pattern on the ground. The shape of this pattern strongly
depends on the longitudinal development of the shower. We reconstruct Xmax by
fitting two-dimensional intensity profiles, simulated with CoREAS, to data from
the LOFAR radio telescope. In the dense LOFAR core, air showers are detected by
hundreds of antennas simultaneously. The simulations fit the data very well,
indicating that the radiation mechanism is now well-understood. The typical
uncertainty on the reconstruction of Xmax for LOFAR showers is 17 g/cm^2.
