We show that the properties of the electron beam and bright X-rays produced by a laser wakefield accelerator can be predicted if the distance over which the laser self-focuses and compresses prior to self-injection is taken into account. A model based on oscillations of the beam inside a plasma bubble shows that performance is optimised when the plasma length is matched to the laser depletion length. With a 200~TW laser pulse this results in an X-ray beam with median photon energy of 20 keV, $> 10^{9}$ photons per shot and a peak brightness of $4 \times 10^{23}$ photons s$^{-1}$ mrad$^{-2}$ mm$^{-2}$ (0.1 % BW)$^{-1}$.