Optimum beam creation in photoinjectors using space-charge expansion